简体   繁体   English

在cloudformation中添加lambda条件?

[英]Add lambda conditions in cloudformation?

I am building my Cloudformation template to create an S3 Bucket. 我正在构建Cloudformation模板以创建S3存储桶。

I wanted to create folders in the bucket at the same time but I have read that I need to use a lambda backed resource. 我想同时在存储桶中创建文件夹,但我已阅读到我需要使用lambda支持的资源。

So I've prepared the lambda part of my template but I need to add a condition : 所以我已经准备好模板的lambda部分,但是我需要添加一个条件:

  • If the lambda refers to a bucket which already exists 如果lambda指的是已经存在的存储桶

  • The bucket already exists and it has been created in this ( everything has to reside in one cloudformation stack) file 该存储桶已经存在,并且已在文件中创建(所有内容都必须驻留在一个cloudformation堆栈中)

  • Call the lambda to create my folders. 调用lambda创建我的文件夹。

I do not want to check if my bucket exists in S3 or if my folders already exist as S3 objects in the bucket. 我不想检查我的存储桶是否存在于S3中,或者我的文件夹是否已作为存储桶中的S3对象存在。

I would like the lambda backed resource to be created after the bucket has been created. 我希望在创建存储桶之后创建由lambda支持的资源。

First of all - why you need directories at all? 首先-为什么需要目录? S3 is in fact a key-value store, "paths" are just prefixes. S3实际上是键值存储,“路径”只是前缀。 Usually there is no benefit of doing so other than human-friendly presentation. 通常,这样做除了人类友好的演示文稿之外没有其他好处。

Secondly - you can either use DependsOn to enforce proper order or resources provisioning, or (that would be a good practice I think) if you make Lambda generic and accept bucket name in your custom resource parameter, you just do it by using the Ref function, which implicitly creates dependency. 其次-您可以使用DependsOn来强制执行正确的订单或资源配置,或者(我认为这是一个好习惯),如果您使Lambda通用并在您的自定义资源参数中接受存储桶名称,则只需使用Ref函数即可,这会隐式创建依赖关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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