-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscriot.py
31 lines (23 loc) · 949 Bytes
/
scriot.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
from datetime import datetime
import boto3
def lambda_handle(event, context):
ec2_client = boto3.client('ec2')
regions = [regions['RegionName']
for region in ec2_client.describe_regions()['Regions']]
for region in regions:
print('Instances in EC2 Region {0}:'.format(region))
ec2 = boto3.resource('ec2', region_name=region)
instances = ec2.instances.filter(
Filters=[
{'Name': 'tag:backup', 'Values': ['true']}
]
)
timestamp = datetime.utcnow().replace(microsecond=0).isoformat()
for i in instances.all():
for v in i.volumes.all():
desc = 'Backup of {0}, volume {1}, created {2}'.format(
i.id, v.id, timestamp
)
print(desc)
snapshot = v.create_snapshot(Description=desc)
print("Created snapshot", snapshot.id)