2017-03-24 11 views
3

チームメンバーで、nodejsラムダバックアップされたカスタムリソースを持つCloudFormationスタックがあります。ラムダのカスタムトリガーを使用したAWS CloudFormationの更新

ラムダ/パラメータ/トリガーを更新すると、Lambdaは最初に作成した第三者のリソースを削除し、新しいパラメータに基づいて新しいものを作成します。

ラムダのexports.handlerがここにあります。

if (event.RequestType == "Delete") { 
    console.log("Request type == Delete") 
    var successCallback = function(event, context) { 
     sendResponse(event, context, "SUCCESS"); 
    } 
    doDeleteThings(event, context, successCallback); 
} else if (event.RequestType == "Create") { 
    console.log("request type == create") 
    doCreateThings(event, context); 
} else if (event.RequestType == "Update") { 
    console.log("request type == update") 
    var successCallback = function(event, context) { 
     doCreateThings(event, context); 
    } 
    doDeleteThings(event, context, successCallback); 
} else { 
    sendResponse(event, context, "SUCCESS"); 
} 

私たちは、コードをテストしているし、それは我々が設定スタックレスモード(で作成し、CloudFormationに削除、作成、削除、および更新の両方で動作します:event.RequestType = process.env.RequestTypeとsendResponse doesnの通常のCloudFormationレスポンスではなく、代わりにcontext.done()を実行しますが、CloudFormationの更新では動作しないようです。私は、ラムダの「アップデート」が何をすべきか誤解していると思っています。

これまでCloudFormationで作成されたLambda関数のCloudWatchログは見られませんでした。

"ManageThirdPartyResources": { 
     "Type": "AWS::Lambda::Function", 
     "Properties": { 
      "Code": { 
       "S3Bucket": "<bucketname>", 
       "S3Key": "<zipname>.zip" 
      }, 
      "Description": { "Fn::Join": ["", ["Use cloudformation to automatically create third party resources for the ", { "Ref": "ENV" }, "-", { "Ref": "AWS::StackName" }, " environment"]] }, 
      "Environment": { 
       "Variables": { 
        <environment variables that will probably be the things changing.> 
       } 
      }, 
      "FunctionName": { 
       "Fn::Join": ["_", [{ "Ref": "AWS::StackName" }, "ManageThirdPartyResources"]] 
      }, 
      "Handler": "index.handler", 
      "Role": "<role>", 
      "Runtime": "nodejs4.3", 
      "Timeout": 30 
     } 
    }, 
    "ThirdPartyResourcesTrigger": { 
     "Type": "Custom::ThirdPartyResourcesTrigger", 
     "Properties": { 
      "ServiceToken": { "Fn::GetAtt": ["ManageThirdPartyResources", "Arn"] } 
     } 
    }, 

ありがとう:

はここCloudFormationテンプレートの相対的な部分です!

答えて

3

のいずれかが変更された場合、更新がCustom::ThirdPartyResourcesTriggerでトリガーされます。ラムダ関数のプロパティが変更された場合、でなく、Custom::ThirdPartyResourcesTriggerで更新をトリガーします。

Custom::ThirdPartyResourcesTriggerで更新をトリガーする場合は、そのプロパティを変更する必要があります。たとえば、ThingNameと呼ば​​にプロパティを追加することができ、あなたがThingNameの値を変更するたびに、あなたのラムダはUpdate要求タイプで呼び出されます:ロギング用として

"ThirdPartyResourcesTrigger": { 
    "Type": "Custom::ThirdPartyResourcesTrigger", 
    "Properties": { 
     "ServiceToken": { "Fn::GetAtt": ["ManageThirdPartyResources", "Arn"] }, 
     "ThingName": "some value" 
    } 
}, 

、想定さIAM役割を確認してくださいあなたのラムダ関数は、CloudWatchログに必要な権限を持っています:

"Effect": "Allow" 
"Action": "logs:*" 
"Resource": "arn:aws:logs:*:*:*" 
+0

ログの事は神からのメッセージでした。 あなたの解決策はうまくいっていたようですが、何かがラムダをすぐに削除して呼び出されるようになったので、それを把握しなければなりませんが、本当に近いです。 –

関連する問題