Automate AWS Infrastructure with Boto 3

 When I first joined a Software Design team, I realized there were a lot of simple AWS infrastructure changes that took up a large chunk of our engineering team’s time. I didn’t want to spend my valuable coding time on these manual, yet essential, tasks so I set out on a mission to automate them. Since I had wanted to build my Python scripting skills anyway, I discovered a way to solve two problems at once — using the software development kit Boto 3 to automate my simple, manual AWS tasks using Python.

Writing the Script

for instance in instances:
print(instances['Instances'][0]['InstanceId']
instance_ids = []for instance in instances:
instance_ids.append(instance['Instances'][0]['InstanceId'])
tag_creation = ec2_client.create_tags(
Resources =
instance_ids,
Tags = [
{
'Key': 'operatingHours',
'Value': 'start=(M-S,0);stop=(M-F,8);tz=et'
}
]
)
response = ec2_client.describe_instances(
Filters = [
{
'Name': 'group-name',
'Values': [
'security-test',
]
},
]
)

Comments