2017-03-03 10 views
2

テンプレートを作成しています。これは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

答えて

0

あなたは同じCFテンプレートにラムダ関数を作成していますか?

私はこれを詳しく見ていませんが、ラムダ関数が作成を完了したことを雲の形で知らせるための要件を満たしていないというのが最初の印象です。

CFの "response.SUCCESS"レスポンスがCFに送り返されていないという鍵があります。 CFはラムダ関数を作成しますが、成功したことを知る必要があります。

これはnode.jsで行う方法ですが、私はpythonの構文を知らないのです。

response.send(event, context, response.SUCCESS, responseData); 

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html

を参照してください。
関連する問題