I am trying to list all the images which has the name Ansible*.
If i can pull it off, i can use it to clean my AMI's that are created during patching activity. i am trying it via SSM Automation Document. below is the code i have.
description: This document is to remove AMI
schemaVersion: '0.3'
assumeRole: '{{ AutomationAssumeRole }}'
mainSteps:
- name: getImageId
action: 'aws:executeAwsApi'
inputs:
Service: ec2
Api: DescribeImages
Filters:
- Name: 'name'
Values:
- 'Ansible*'
outputs:
- Name: ImageId
Selector: '$.Images[0].ImageId'
Type: String
here, Selector: '$.Images[0].ImageId' gives only the 1st image id of the list. i can get it if i can give something like Selector: '$.Images[*].ImageId' but this is not supported by the SSM document.
could someone please help me on this. all i want is, i want to list all the images with its AMI ID.
PS: i have the shell and python script which does the job,. but i am looking for AWS SSM Automation document due to roles and policy restrictions
From some quick testing I'm not sure you can.
You can do this on the CLI though, so perhaps you can use the
boto3
library and do it as a Python script via theexecuteScript
automation?CLI command that works:
Update:
Here's an automation doc that runs the python script:
Be sure to change things like region, search string, etc.