AWS Lambda Function to List all Volumes in AWS User ID before Backup

import boto3

def lambda_handler(event, context):
# TODO implement
userID='%%%%%%%' # redundancy user account ID
ec2 = boto3.client('ec2')
volumes = ec2.describe_volumes()
ec2Resource=boto3.resource('ec2')
for volume in volumes['Volumes']:
for attachment in volume['Attachments']:
instance=ec2Resource.Instance(attachment[u'InstanceId'])
instanceName=instance.tags[0][u'Value']
print "Backing up %s in %s" % (volume['VolumeId'], volume['AvailabilityZone'])
break
snapshots = ec2.describe_snapshots(Filters=[{ 'Name': 'owner-id','Values':[userID] }])
for snapshot in snapshots['Snapshots']:
print "Backing up %s in %s" % (instanceName, snapshot['SnapshotId'], volume['AvailabilityZone'])
VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Tags: AWS, lamda, python

Trackback from your site.