I'm newer to Python programming, and am trying to develop an AWS Lambda. It's written in Python 3.6 that creates snapshots of available EBS volumes for deletion at a later time using boto3 calls. I want the logic for the Lambda to iterate over the volume tags. If there's a specific tag in the list of tags, then process some evaluation logic based off a date for the volume to be deleted. If no specified tag exists in collection, or tags is None proceed with creating snapshot.
My Lambda will work with the logic for the specified tag and creating a snapshot fine. I'm struggling with the correct loop syntax to handle all volume tags as a dictionary. It wants to loop through each tag individually for the volume vs. all at once as a collection.
for vol in ec2.volumes.all():
if vol.state == 'available':
volid = vol.id
tags = {}
for tag in vol.tags:
if tag['Key'] == 'DeleteMeAfter':
print("===================")
print(", ".join((
volid,
tag['Key'],
tag['Value']
)))
### Process additional logic on tag['Value'] ###
When I add an elif/else statement to the if tag statement it tries to create multiple snapshots of the same volume.
"An error occurred (SnapshotCreationPerVolumeRateExceeded) when calling the CreateSnapshot operation: The maximum per volume CreateSnapshot request rate has been exceeded."
Any help would be greatly appreciated!