Lambda支持的自定义资源 [英] Lambda-Backed Custom Resource

查看:105
本文介绍了Lambda支持的自定义资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在CFT中创建自定义资源,该资源将在创建所述模板时运行lambda函数。我看过有关Lambda支持的自定义资源的AWS文档,但是由于该文档不是特别冗长,因此我对该主题仍然有些困惑。我已经为自己的自定义资源添加了JSON,我只是想知道是否还有其他事情要做,以确保该资源在创建模板时会调用函数。

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"
                    ]
                }
            }

注意:它引用的Lambda函数从中获取CSV一个S3资源,并使用该信息来创建和填充DynamoDB表。

推荐答案

调用函数,假设CloudFormation模板包含一个名为 DistroDBPop 的Lambda函数。

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

如果您查看演练:查找Amazon Machine Image ID- AWS CloudFormation ,您还将看到其他一些元素:

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


  • Lambda函数

  • Lambda函数的角色

  • Lambda函数中的特殊回调,指示它已完成

有一个很好的Lambda示例代码,位于: stelligent / cloudformation-custom-资源-GitHub

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

还有一个 cfnresponse 模块,该模块使结尾处的回调更加容易Lambda函数。请参阅: cfn响应模块

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

最后,确保Lambda函数了解它可能在堆栈的创建,更新和删除时调用,因此它可能需要忽略某些事件除非它们是相关的。

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.

这篇关于Lambda支持的自定义资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆