小编nik*_*kra的帖子

自定义资源 (lambda) 调用后 AWS CloudFormation 事件挂在 CREATE_IN_PROGRESS 状态

我有一个 lambda,它有一个 python 脚本来在参数存储中创建 application.properties 文件。我有一个 cloudformation 模板,它调用此 lambda 来创建 application.properties。我的云信息模板如下所示:

{
   "Description": "Create SSM Parameter",
   "Resources": {
      "primerinvoke": {
         "Type": "AWS::CloudFormation::CustomResource",
         "Properties": {
            "Handler": "lambda_function.lambda_handler",
            "ServiceToken": "arn:aws:lambda:us-east-1:1234:function:test_lambda",
            "FunctionName": "test_lambda"
         }
      }
   }
}
Run Code Online (Sandbox Code Playgroud)

我创建SSM参数的python脚本(其路径是:/myapp/dev/test/application.properties)是:

import boto3
import os

region = os.environ['AWS_REGION']
client = boto3.client('ssm')
def ssm_create():
    response = client.put_parameter(Name='/myapp/'
                                    + os.environ['environment']
                                    + '/test/application.properties',
                                    Description='string',
                                    Value='APPLICATION_NAME=myapp',
                                    Type='SecureString', Overwrite=True)
    return response
def lambda_handler(event, context):
    PutParameterResult = ssm_create()
Run Code Online (Sandbox Code Playgroud)

我按照AWS lambda: No module named 'cfnresponse'import cfnresponse中的建议使用,但是导入不起作用,而且我不知道如何在 lambda 外部安装 cfnresponse 库。 …

python aws-cloudformation aws-lambda

5
推荐指数
1
解决办法
6146
查看次数

标签 统计

aws-cloudformation ×1

aws-lambda ×1

python ×1