Skip to content

Instantly share code, notes, and snippets.

@OksanaH
Created January 29, 2022 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OksanaH/256ab38d178bf3865fe9d95eaeca6657 to your computer and use it in GitHub Desktop.
Save OksanaH/256ab38d178bf3865fe9d95eaeca6657 to your computer and use it in GitHub Desktop.
lambda.py
def imagesUsedInEC2s(region):
print(f'Checking instances that are not in ASGs in region {region}...')
amis = []
ec2_resource = boto3.resource('ec2', region_name = region)
instances = ec2_resource.instances.filter(
Filters=
[
{
'Name': 'instance-state-name',
'Values': [ 'running' ]
}
])
for instance in list(instances):
amis.append(instance.image_id)
return amis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment