I am trying to get list of all the available snapshots in AWS account. I have written following code.
def lambda_handler(event, context):
ec2 = boto3.client('ec2')
resp_describe_snapshots = ec2.describe_snapshots(OwnerIds=['self'])
snapshot = resp_describe_snapshots['Snapshots']
snapshots = {}
os.chdir('/tmp')
for snapshotIdList in resp_describe_snapshots['Snapshots']:
snapid = snapshotIdList.get('SnapshotId')
Des = snapshotIdList.get('Description')
sttime = snapshotIdList.get('StartTime').strftime("%b %d %Y")
#print(snapshotIdList.get('SnapshotId')+ ","+ snapshotIdList.get('Description')+ ","+ snapshotIdList.get('StartTime').strftime("%b %d %Y"))
for response in ec2.get_paginator('describe_snapshots').paginate(OwnerIds=['self'],Filters=[{'Name': 'tag:Name','Values': ['Ubuntu']}]):
snapshots.update([(snapshot['SnapshotId'], snapshot) for snapshot in response['Snapshots']])
print(snapshots)
How can I list all the snapshots ID and it's creation date ?
I also want to create a csv file.