-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-env-tags.py
44 lines (35 loc) · 1.14 KB
/
add-env-tags.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
import boto3
ec2_client_paris = boto3.client('ec2', region_name="eu-west-3")
ec2_resource_paris = boto3.resource('ec2', region_name="eu-west-3")
ec2_client_frankfurt = boto3.client('ec2', region_name="eu-central-1")
ec2_resource_frankfurt = boto3.resource('ec2', region_name="eu-central-1")
instance_ids_paris = []
instance_ids_frankfurt = []
reservations_paris = ec2_client_paris.describe_instances()['Reservations']
for res in reservations_paris:
instances = res['Instances']
for ins in instances:
instance_ids_paris.append(ins['InstanceId'])
response = ec2_resource_paris.create_tags(
Resources=instance_ids_paris,
Tags=[
{
'Key': 'environment',
'Value': 'prod'
},
]
)
reservations_frankfurt = ec2_client_frankfurt.describe_instances()['Reservations']
for res in reservations_frankfurt:
instances = res['Instances']
for ins in instances:
instance_ids_frankfurt.append(ins['InstanceId'])
response = ec2_resource_frankfurt.create_tags(
Resources=instance_ids_frankfurt,
Tags=[
{
'Key': 'environment',
'Value': 'dev'
},
]
)