Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fetch latest version of SSM parameter on Cloudformation Yaml file

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.

like image 253
virusivv Avatar asked Nov 07 '25 13:11

virusivv


1 Answers

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
like image 95
Vikyol Avatar answered Nov 09 '25 06:11

Vikyol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!