Lab 06: Multi Region Latest AMI


Consider the use case of deploying your current template in different regions. You would need to manually change AmiID property in your template to match the AMI ID for each AWS Region. Similarly, if there is an update to the Amazon Machine Image, and you would like to use the latest image, the same manual process would apply.

To fix this, you can use the existing Parameters section of your CloudFormation template and define Systems Manager parameter type. A Systems Manager parameter type allows you to reference parameters held in the System Manager Parameter Store.

Topics Covered

In this Lab, you will learn:

Start Lab

  1. Go to the code/30-launching-ec2 directory.

  2. Open the 01-lab06-SSM.yaml file.

  3. Update the AmiID parameter to:

        Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
        Description: The ID of the AMI.
        Default: '/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2'

Go to the AWS console and update your stack with a new template.

  1. Open the AWS CloudFormation link in a new tab and log in to your AWS account.
  2. Click on the stack name, for example cfn-workshop-ec2.
  3. In the top right corner click on Update.
  4. In Prepare template, choose Replace current template.
  5. In Template source, choose Upload a template file.
  6. Click on Choose file button and navigate to your workshop directory.
  7. Select the file 01-lab06-SSM.yaml and click Next.
  8. For Amazon Machine Image ID copy and paste in /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2
  9. For EnvironmentType select the different environment than is listed. For example if you have Dev selected, choose Test and click Next.
  10. You can leave Configure stack options default, click Next.
  11. On the Review <stack_name> page, scroll down to the bottom and click on Update stack.
  12. You can click the refresh button a few times until you see in the status UPDATE_COMPLETE.
How do I update a Stack?


Deploy the template in different AWS Region to the one you have been using.


Notice, that you did not have to update AMI ID parameter. By using CloudFormation’s integration with Systems Manager Parameter Store, your templates are now more generic and reusable.


Congratulations! You have now successfully updated your template to use the latest Amazon Linux AMI. Furthermore, your template can now be deployed in any region, without appending AMI ID parameter.