2
votes

I have a Cloudformation Yaml file where it creates a lot of resources, one of them is an EC2 with Windows. My problem is I need to have this automated selection of the latest AMI, I made a Lambda function where it retrieves newest AMI ID and stores in an SSM parameter, then using the Cloudformation with YAML template I can access to ssm using the following command

{{resolve:ssm:parameter_name:version_number_int}}

but my problem is that it's not always the same version number, it will be changed everytime when there will be a new AMI, is there any method where I can write to get always the latest version? or to stop versioning or anything?

Thanks.

1
Related feature request: github.com/aws-cloudformation/…Pat Myron
thanks for commenting, the best result for this task is the answer I choose, it doesn't depend on creating lambda or any other scripts to update custom SSM parameter for the latest AMI ID of windows when there is already a pre defined public SSM parameter!virusivv

1 Answers

1
votes

SSM Parameter Store provides public parameters to retrieve latest AMIs.

# Use public Systems Manager Parameter
Parameters:
  LatestAmiId:
    Type: 'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>'
    Default: '/aws/service/ami-windows-latest/Windows_Server-2019-English-Full-Base'

Resources:
 Instance:
    Type: 'AWS::EC2::Instance'
    Properties:
      ImageId: !Ref LatestAmiId