Skip to content

Instantly share code, notes, and snippets.

@dasgoll
Created October 28, 2019 16:42
Show Gist options
  • Save dasgoll/6b69f7808b73be6d2d95ab1f35e6f270 to your computer and use it in GitHub Desktop.
Save dasgoll/6b69f7808b73be6d2d95ab1f35e6f270 to your computer and use it in GitHub Desktop.
fetch latest ami
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