Reputation: 684
AWS CloudFormation template allow to select AMI Image ID for EC2 instance using construction like this
ECSAMI:
Description: AMI ID
Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
Default: /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2
But I can not find parameter path that will point to the specific version of AMI Image. For example AMI ID for ECS can be queried by this path, that point to the specific version:
/aws/service/ecs/optimized-ami/amazon-linux-2/amzn2-ami-ecs-hvm-2.0.20181112-x86_64-ebs/image_id
How I can query not the latest AMI image id for EC2? Or where I can full "tree" or paths list of publicly available parameters? I want something like this
/aws/service/<ec2>/<amazon-linux-2>/<image-version>
Upvotes: 1
Views: 1185
Reputation: 269282
The special SSM method you show in your question is provided by AWS to make it easy for users to access the latest version of specific AMIs. The information is published into Parameter Store.
The alternative method is to hard-code the value of the desired AMI in the section of the template that defines the EC2 instance. You will often see example templates that use a Mapping to have different AMI values for each region.
There is no capability to request the a specific AMI aside from provide the actual AMI ID.
Why is this? It is because the SSM method was added as a convenience way of referring to the "latest" or "recommended" AMI. Some background process publishes the appropriate AMI IDs to SSM. It is not intended as a method for cataloging all AMIs.
If you really need to search by name, you could create a CloudFormation Custom Resource using AWS Lambda that queries available AMIs by name and then returns the appropriate AMI ID.
Upvotes: 2