Lambda-Backed Custom Resource

末鹿安然 提交于 2019-12-13 01:18:10

问题


I'm trying to create a custom resource in a CFT that will run a lambda function on creation of said template. I've looked at the AWS documentation for Lambda-Backed Custom Resources, but I'm still a bit confused on the topic as the documentation was not particularly verbose. I've included the JSON for my custom resource, and I'm just wondering if there's anything else I have to do in order to ensure that this resource will call on the function upon creating the template.

"LambdaRunner": {
            "Type": "AWS::CloudFormation::CustomResource",
            "Properties": {
                "ServiceToken": {
                    "Fn::GetAtt": [
                        "DistroDBPop",
                        "Arn"
                    ]
                }
            }

Note: The Lambda function it references takes a CSV from an S3 resource and uses the information to create and populate a DynamoDB table.


回答1:


That looks sufficient as far as calling the function, assuming that the CloudFormation template contains a Lambda function called DistroDBPop.

If you look at Walkthrough: Looking Up Amazon Machine Image IDs - AWS CloudFormation, you'll see that several other elements are also needed:

  • The Lambda function
  • A Role for the Lambda function
  • A special callback in the Lambda function to indicate that it has completed

There's some good example Lambda code at: stelligent/cloudformation-custom-resources - GitHub

There is also a cfnresponse module that makes it easier to callback at the end of the Lambda function. See: cfn-response Module

Finally, make sure the Lambda function understands that it might be called at Create, Update and Delete of the stack, so it might need to 'ignore' certain events unless they are relevant.



来源:https://stackoverflow.com/questions/54951224/lambda-backed-custom-resource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!