简体   繁体   English

如何仅在创建 AWS::Cloudformation::Stack 时调用 AWS::Lambda::Function?

[英]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.我有一个包含 VPC 和 RDS 实例的堆栈。

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.我想创建一个新堆栈(通过一个单独的模板),它在创建时调用一个 lambda 函数,该函数连接到上述 RDS 实例并创建一个新数据库。

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.我只希望 lambda 在第一次创建堆栈时调用,以避免运行 lambda 来创建已经存在的数据库。

Additional Information附加信息

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.

相关问题 我如何运行AWS Lambda函数以使我知道CloudFormation已完成整个堆栈的创建 - How do I run a AWS Lambda function to let me know that CloudFormation has completed the entire stack creation 如何在 AWS Lambda 中加载 AWS Cloudformation 的 Output? - How Can I Load The Output of AWS Cloudformation In AWS Lambda? 如何找到 AWS CloudFormation 堆栈创建失败的根本原因? - How can I find the root cause for AWS CloudFormation stack creation failure? 如何在 VPC 内连接 AWS lambda 以连接到 cloudformation 堆栈? - How can I connect an AWS lambda inside a VPC to connect to a cloudformation stack? 如何在 cloudformation lambda 中为 aws lambda 设置最大重试次数? - How can i set the maximumRetryAttempt for aws lambda in the cloudformation lambda? AWS CloudFormation中的Lambda函数 - Lambda Function in AWS CloudFormation 我可以使用 CloudFormation 模板更新 AWS Lambda function 吗? - Can I update AWS Lambda function using CloudFormation template? 如何使用 CloudFormation 模板更新 AWS Lambda function - How do I update AWS Lambda function using CloudFormation template 如何使用aws中的cloudformation在api网关中请求参数并将其传递给lambda函数? - How can I request parameters in api gateway using cloudformation in aws and pass it down to lambda function? 在Amazon AWS中,如何仅在ELB的实例状态从InService转换为OutOfService时调用Lambda函数来执行? - In Amazon AWS, how can I invoke a Lambda Function to execute only when an ELB's instance state transitions from InService to OutOfService?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM