Skip to content

How do I troubleshoot issues when my Amazon S3 Event Notifications don't invoke my Lambda function?

4 minute read
0

I configured Amazon Simple Storage Service (Amazon S3) Event Notifications to invoke my AWS Lambda function. However, the function doesn't invoke when the Amazon S3 event occurs.

Short description

To troubleshoot, use the AWSSupport-TroubleshootLambdaS3Event for AWS Systems Manager automation runbook. Or, manually troubleshoot your Lambda function.

Resolution

Run the Systems Manager automation runbook

Prerequisite: Before you start the runbook, make sure that your AWS Identity and Access Management (IAM) user or role has the required permissions. For more information, see the Required IAM permissions section of AWSSupport-TroubleshootLambdaS3Event.

Complete the following steps:

  1. Open the Systems Manager console.

  2. In the navigation pane, choose Documents.

  3. In the search bar, enter AWSSupport-TroubleshootLambdaS3Event.

  4. Select AWSSupport-TroubleshootLambdaS3Event.

  5. Choose Execute Automation.

  6. Choose Execute.

    Note: It can take up to 15 minutes for the test to complete. For a list of the steps that the runbook performs, see the Document steps section of AWSSupport-TroubleshootLambdaS3Event.

Manually troubleshoot Lambda function

Note: If you receive errors when you run AWS Command Line Interface (AWS CLI) commands, then see Troubleshooting errors for the AWS CLI. Also, make sure that you're using the most recent AWS CLI version.

Confirm that your Amazon S3 event types configured correctly

When you configure S3 Event Notifications, you must specify each event type that causes Amazon S3 to send the notification. If an event type that you didn't specify occurs in your Amazon S3 bucket, then Amazon S3 doesn't send the notification.

For example, you configure an event notification to invoke Lambda with the s3:ObjectCreated:Put event type. If you upload a large file, then Amazon S3 automatically uses the multipart upload process to upload the file to the bucket. To invoke the Lambda function for this upload, you must also configure the s3:ObjectCreated:CompleteMultipartUpload event type. Or, use the s3:ObjectCreated:* event type to request notifications for each API that Amazon S3 uses to create an object.

Confirm that your object key name filters include the uploaded file name

If your S3 Event Notifications use object key name filtering, then Amazon S3 publishes notifications only for objects with specific prefixes or suffixes. Make sure that the prefix or suffix filters specified in the event notification include the uploaded object key name. Also, make sure that your Lambda function is in the same AWS Region as your S3 bucket.

Note: You can't use a wildcard character (*) in filters as a prefix or suffix to represent a character.

For object key name filtering, certain special characters in your prefixes or suffixes must be URL-encoded or percent-encoded. For example, to define the value of a prefix as test=abc/, enter the test%3Dabc/ URL-encoded value.

For more information on specific character handling in object key names, see Object key naming guidelines.

Confirm that your Lambda function's IAM resource-based policy has the required permissions for Amazon S3 to invoke the function

Check your Lambda function's IAM resource-based policy to confirm that the policy allows your bucket to invoke the function. If the bucket can't invoke the function, then add the required policy.

Example policy:

{
  "Version": "2012-10-17",
  "Id": "default",
  "Statement": [
    {
      "Sid": "lambda-allow-s3-my-function",
      "Effect": "Allow",
      "Principal": {
        "Service": "s3.amazonaws.com"
      },
      "Action": "lambda:InvokeFunction",
      "Resource": "arn:aws:lambda:us-east-2:123456789012:function:my-function",
      "Condition": {
        "StringEquals": {
          "AWS:SourceAccount": "123456789012"
        },
        "ArnLike": {
          "AWS:SourceArn": "arn:aws:s3:::amzn-s3-demo-bucket"
        }
      }
    }
  ]
}

For more information, see Managing permissions in AWS Lambda.

Note: When you use the Amazon S3 console to add a new event notification, Amazon S3 automatically adds the required permissions to your function's resource-based policy. However, if you use the put-bucket-notification-configuration AWS CLI command to add an event notification, then your function's policy isn't updated automatically.

Confirm that your Lambda functions configured to handle concurrent invocations from S3 Event Notifications

You must configure your Lambda function to handle concurrent invocations from S3 Event Notifications. If invocation requests arrive faster than your function can scale or your function is at maximum concurrency, then Lambda throttles the requests.

For more information, see Invoking a Lambda function asynchronously.

Related information

How do I use AWS Systems Manager Automation to troubleshoot issues when my Amazon S3 event notification doesn't invoke a Lambda function?

Process Amazon S3 event notifications with Lambda

Tutorial: Using an Amazon S3 trigger to invoke a Lambda function

Why do I get the error "Unable to validate the following destination configurations" when I use Amazon S3 Event Notifications with general purpose buckets?

How do I set up an Amazon S3 Event Notification to invoke a Lambda function that's in another AWS account?

AWS OFFICIALUpdated 2 months ago