cloud config_error ai_generated true

Missing S3 event notification for Lambda trigger: S3 bucket 'my-bucket' has no event notification configuration for Lambda function 'my-function'

ID: cloud/aws-lambda-s3-event-source-missing-notification

Also available as: JSON · Markdown · 中文
95%Fix Rate
88%Confidence
1Evidence
2023-11-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
aws_cli active
lambda_runtime active
s3 active

Root Cause

The S3 bucket does not have an event notification configured to invoke the Lambda function, often due to manual deletion of the notification or incorrect bucket policy.

generic

中文

S3 存储桶未配置事件通知以调用 Lambda 函数,通常是由于手动删除了通知或存储桶策略不正确。

Official Documentation

https://docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html

Workarounds

  1. 95% success Use AWS CLI to add the event notification: `aws s3api put-bucket-notification-configuration --bucket my-bucket --notification-configuration file://config.json` where config.json contains: `{"LambdaFunctionConfigurations": [{"LambdaFunctionArn": "arn:aws:lambda:us-east-1:123456789012:function:my-function", "Events": ["s3:ObjectCreated:*"]}]}`
    Use AWS CLI to add the event notification: `aws s3api put-bucket-notification-configuration --bucket my-bucket --notification-configuration file://config.json` where config.json contains: `{"LambdaFunctionConfigurations": [{"LambdaFunctionArn": "arn:aws:lambda:us-east-1:123456789012:function:my-function", "Events": ["s3:ObjectCreated:*"]}]}`
  2. 85% success Check and update the Lambda resource-based policy to allow S3 invoke: `aws lambda add-permission --function-name my-function --statement-id s3-invoke --action lambda:InvokeFunction --principal s3.amazonaws.com --source-arn arn:aws:s3:::my-bucket`
    Check and update the Lambda resource-based policy to allow S3 invoke: `aws lambda add-permission --function-name my-function --statement-id s3-invoke --action lambda:InvokeFunction --principal s3.amazonaws.com --source-arn arn:aws:s3:::my-bucket`

中文步骤

  1. Use AWS CLI to add the event notification: `aws s3api put-bucket-notification-configuration --bucket my-bucket --notification-configuration file://config.json` where config.json contains: `{"LambdaFunctionConfigurations": [{"LambdaFunctionArn": "arn:aws:lambda:us-east-1:123456789012:function:my-function", "Events": ["s3:ObjectCreated:*"]}]}`
  2. Check and update the Lambda resource-based policy to allow S3 invoke: `aws lambda add-permission --function-name my-function --statement-id s3-invoke --action lambda:InvokeFunction --principal s3.amazonaws.com --source-arn arn:aws:s3:::my-bucket`

Dead Ends

Common approaches that don't work:

  1. 50% fail

    The console may not create the notification if the bucket already has a notification limit (max 100) or if permissions are insufficient.

  2. 80% fail

    The bucket policy is independent of event notifications; the notification itself must be configured via S3 API.