Dynamic created resources in CloudFormation template

0

I am learning CloudFormation with some basic resources : VPC, subnet, EC2,.. and have some questions:

  1. How to define to create 1, 2 or 3 EC2 for each time creates stacks with only one template. Each EC2 will have differences properties (EBS size, AMI,...)?
  2. How to define Yes/No resources. For example, if I choose Yes in Parameter, this resources will be created. And if I choose No, this resources will not be created. Thank you so much for your help.
已提问 7 个月前308 查看次数
2 回答
0
  1. For complex requirements like this - where you might want to loop through a set of resources and assign different properties to each one you might want to look at CDK. For simpler requirements you might look at the ForEach intrinsic function.
  2. Have a look at conditionally creating resources.
profile pictureAWS
专家
已回答 7 个月前
profile pictureAWS
专家
已审核 7 个月前
0

you can define your EC2 properties as mappings in the beginning of your cloudformation template, something like this:

Mappings: AMI_Mappings: EC2Name: ec21: ami21 ec22: ami22 ec23: ami23 ec24: ami24 ec25: ami25

and use Fn::ForEach intrinsic function to loop through these properties and define the EC2 resource inside the loop.

已回答 7 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则