1

I am having a template where I am creating a Ubuntu EC2 instance based on the region and the associated image id mapped in the template.Is there anyway through which the the latest Ubuntu image id will get selected based on the region.This will happen during template execution.It would be helpful to get any sample template for the same.

Amit Chandra
  • 61
  • 1
  • 1
  • 3

1 Answers1

2

There are few ways you can achieve this:

A) You can use the Mappings section of the template to specify an AMI for each region. You would then use Fn::FindInMap to retrieve the value of the AMI according to the evaluation of the pseudo parameter AWS::Region.

See:

B) You can use a lambda backed custom resource to retrieve the latest ubuntu AMI during stack creation. There is a getting started guide for the same, you can use it as a starting point.

See: Walkthrough: Looking Up Amazon Machine Image IDs - AWS CloudFormation

C) If you can migrate to an Amazon Linux AMI, based on RHEL, you can reference public systems manager parameters for the latest AMI id for that region. I have an example template in github you can use as a reference.

See: CloudFormationExamples/highlyavailable-asg-lamp-server-alb at master · smith-b/CloudFormationExamples

smithers
  • 41
  • 2