AWS Lambda Function Triggers on S3 Event, But only Once in About 30 Mins

0

I have created a simple Lambda function to trigger upon creation of an object in S3 bucket, but it does not always trigger...

The function triggers and generates a log in CloudWatch when I upload a file to the bucket. However, when I upload the same or a different file about a minute later to the same bucket, the function does not trigger again.

If I re-save the function and upload a file to the bucket again, the function triggers again. If I upload the file again a minute or so later, the function does not trigger.

If I actually wait for about 30 mins (not just a min or two) and upload a file again, the function triggers without re-saving.

Below is the function code, Python 3.7. Why it does not trigger any time I upload a file to the bucket?

import json

print("This is a test")

def lambda_handler(event, context):
    # Setting variables to equal values from the event object passed in.
    bucket = event['Records'][0]['s3']['bucket']['name']
    region = event['Records'][0]['awsRegion']
    object = event['Records'][0]['s3']['object']['key']
    user = event['Records'][0]['userIdentity']['principalId']

    print("Bucket: " + bucket)
    print("Region: " + region)
    print("User is " + user)

    return(object)

Thank you :)

asked 3 years ago406 views
1 Answer
0

Actually, this is not an issue. Apparently, AWS bundles multiple lambda executions in the same Log Stream in the CloudWatch. So my Lambda function did execute each time I upload a file to the bucket, I just did not notice that the execution was logged in the same Log Stream and instead expected a new Log Stream created for each lambda execution.

answered 3 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions