テンプレートを作成しています。これはDynamoDB table
を作成します。私は、テンプレートのパラメータの値をDynamoDB table
の中に入れたいと思います。そうするために、私は、スタックパラメータを取り、次のようにテーブルの項目に入れラムダ関数を作成しました:カスタムクラウドリソースによってラムダ関数を呼び出せません
import boto3
def lambda_handler(event, context):
parameters = {}
outputs = {}
cf_client = boto3.client('cloudformation')
dynamodb = boto3.resource('dynamodb')
# Get the name of the stack cloudformation
stack_name = context.invoked_function_arn.split(':')[6].rsplit('-', 2)[0]
response = cf_client.describe_stacks(StackName=stack_name)
# Get the outputs of the stack
for r in response['Stacks'][0]['Outputs']:
outputs[r['OutputKey']] = r['OutputValue']
policy_table_name = outputs['PolicyDDBTableName']
# Get the parametres of the stack
for e in response['Stacks'][0]['Parameters']:
parameters[e['ParameterKey']] = e['ParameterValue']
DefaultRetentionDays = parameters['DefaultRetentionDays']
CustomTagName = parameters['CustomTagName']
AutoSnapshotDeletion = parameters['AutoSnapshotDeletion']
response = dynamodb.put_item(
TableName=policy_table_name,
Item={'SolutionName': {'S': 'EbsSnapshotScheduler'},
'DefaultRetentionDays': {'S': DefaultRetentionDays},
'CustomTagName': {'S': CustomTagName},
'AutoSnapshotDeletion': {'S': AutoSnapshotDeletion}
})
はその後、テンプレートcloudformation
に、私は、関数を呼び出すためにcustom resource
を作成:
"PutInDB" : {
"Type" : "Custom::customhelper",
"Properties" : {
"ServiceToken": { "Fn::GetAtt" : ["FunctionHelper" , "Arn"] },
"StackName": {"Ref": "AWS::StackName" }
}
},
関数とその役割も同じスタックに作成されます。
私はスタックにcustom resource
ハングを作成して、エラーで作成に失敗します。
Custom Resource failed to stabilize in expected time
。私はここに何かを逃していますか custom resource
を正常に作成し、その関数を呼び出して、スタックのパラメータがDynamoDB table
の内部に挿入されるようにするにはどうすればよいですか? AWS Documentationから
:
When you associate a Lambda function with a custom resource, the function is invoked whenever the custom resource is created, updated, or deleted