[英]How can I invoke an AWS::Lambda::Function only on the creation of a AWS::Cloudformation::Stack?
I have a stack with a VPC and an RDS instance.我有一个包含 VPC 和 RDS 实例的堆栈。
I want to create a new stack (through a separate template), which upon creation, invokes a lambda function that connects to the aforementioned RDS instance and creates a new database.我想创建一个新堆栈(通过一个单独的模板),它在创建时调用一个 lambda 函数,该函数连接到上述 RDS 实例并创建一个新数据库。
I only want the lambda invokes the first time the stack is created, as to avoid running a lambda to create a database that already exists.我只希望 lambda 在第一次创建堆栈时调用,以避免运行 lambda 来创建已经存在的数据库。
I am using nodejs8.10 runtime for the lambda, and creating the database with the node mysql library.我正在为 lambda 使用 nodejs8.10 运行时,并使用 node mysql 库创建数据库。
My template should allow for only new stacks to create databases on the RDS instance.我的模板应该只允许新堆栈在 RDS 实例上创建数据库。
You can define a Lambda-backed custom resource in CloudFormation.您可以在 CloudFormation 中定义Lambda 支持的自定义资源。 You can check if the resource is being created, updated, or deleted from the function.
您可以检查是否正在从函数中创建、更新或删除资源。 But it'd be best if you can make the function idempotent.
但如果你能让函数幂等就更好了。
In the past I've used this github project to bootstrap a custom resource.过去我使用 这个 github 项目来引导自定义资源。 I recommend it.
我推荐它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.