-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpromote_ami.py
54 lines (47 loc) · 1.1 KB
/
promote_ami.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from boto3 import client
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("ami_id", help="The AMI id that you would like to promote.")
parser.add_argument("account_id", help="The account ID you would like to promote the AMI to.")
args = parser.parse_args()
ami_id = str(args.ami_id)
account_id = str(args.account_id)
client = client('ec2')
client.modify_image_attribute(
ImageId=ami_id,
OperationType='add',
LaunchPermission={
'Add': [
{
'UserId': account_id
}
]
}
)
ami_details = client.describe_images(
ExecutableUsers=[account_id],
ImageIds=[ami_id]
)
snapshot_id = ami_details['Images'][0]['BlockDeviceMappings'][0]['Ebs']['SnapshotId']
client.modify_snapshot_attribute(
CreateVolumePermission={
'Add':[
{
'UserId': account_id
}
]
},
OperationType='add',
SnapshotId=snapshot_id
)
client.create_tags(
Resources=[
ami_id
],
Tags=[
{
'Key': 'PromotedtoProd',
'Value': 'true'
},
]
)