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달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠