Skip to content

Instantly share code, notes, and snippets.

@mcohen01
Last active January 10, 2017 01:29
Show Gist options
  • Save mcohen01/853d0e5d5d3ee36d97dc94dbfbc6666b to your computer and use it in GitHub Desktop.
Save mcohen01/853d0e5d5d3ee36d97dc94dbfbc6666b to your computer and use it in GitHub Desktop.
import boto.ec2
regions = {
'dev': ['us-east-1', 'us-west-2'],
'corp': ['us-east-1', 'us-west-2'],
'outside': ['us-west-1'],
'stage': ['us-east-1', 'us-west-2', 'ap-southeast-2'],
'prod': ['us-east-1', 'us-west-2', 'ap-southeast-2', 'sa-east-1', 'eu-west-1', 'ap-northeast-1', 'ap-southeast-1'],
}
region = 'dev'
for reg in regions[region]:
print('Fetching images in ' + reg)
con = boto.ec2.connect_to_region(reg)
images = con.get_all_images()
print('Found ' + str(len(images)) + ' images in ' + reg)
for image in images:
if 'version' in image.tags and not 'image_version' in image.tags:
print('Adding image_version: ' + image.tags['version'] + ' to ' + image.id)
con.create_tags([image.id], {'image_version': image.tags['version']})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment