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.
feita há 7 meses308 visualizações
2 Respostas
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
ESPECIALISTA
respondido há 7 meses
profile pictureAWS
ESPECIALISTA
avaliado há 7 meses
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.

respondido há 7 meses

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas