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.
preguntada hace 7 meses308 visualizaciones
2 Respuestas
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
EXPERTO
respondido hace 7 meses
profile pictureAWS
EXPERTO
revisado hace 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 hace 7 meses

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas