简体   繁体   中英

How can I invoke an AWS::Lambda::Function only on the creation of a AWS::Cloudformation::Stack?

Background:

I have a stack with a VPC and an RDS instance.

Goal:

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.

Problem:

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.

Additional Information

I am using nodejs8.10 runtime for the lambda, and creating the database with the node mysql library.

My template should allow for only new stacks to create databases on the RDS instance.

You can define a Lambda-backed custom resource in CloudFormation. 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. I recommend it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM