Created
October 28, 2019 16:42
-
-
Save dasgoll/6b69f7808b73be6d2d95ab1f35e6f270 to your computer and use it in GitHub Desktop.
fetch latest ami
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
import json | |
import traceback | |
def handler(event, context): | |
session = boto3.Session(profile_name="sandbox") | |
client = session.client('ec2') | |
response = client('ec2').describe_images( | |
# Owners=[event['ResourceProperties']['Owner']], | |
Filters=[ | |
# {'Name': 'name', 'Values': [event['ResourceProperties']['ImageName']]} | |
{'Name': 'name', 'Values': "jameel"} | |
] | |
) | |
amis = sorted(response['Images'], | |
key=lambda x: x['CreationDate'], | |
reverse=True) | |
id = amis[0]['ImageId'] | |
print(id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment