I have the following lambda function code for simply printing out the Author and metadata of an uploaded event of an S3 bucket:
from __future__ import print_function
s3 = boto3.client('s3')
def lambda_handler(event, context):
#print("Received event: " + json.dumps(event, indent=2))
# bucket = event['Records']['s3']['bucket']['name']
for record in event['Records']:
bucket = record['s3']['bucket']['name']
key = record['s3']['object']['key']
response = s3.head_object(Bucket=bucket, Key=key)
print("Author : " + response['Metadata']['author'])
print("Description : " + response['Metadata']['description'])
However, I am getting the following error while testing:
"for record in event['Records']:"
Am I doing anything wrong while accessing the bucket name and key name of the S3 object? If not, then what am I doing wrong here?