Creating an S3 Bucket with Lambda Events

Hello,

I’m trying to create a lambda function that receives the ObjectCreated Event for an S3 bucket, also created in the stack. I have my LambdaFunction with the S3 event handler, the S3 Bucket Resource, and a LambdaPermission for the bucket. The error I receive when attempting to create this setup is cryptic and not sure if theres anyway to look up exactly whats wrong (SLS_DEBUG=* didn’t help either)

The error is:

An error occurred: S3BucketContent - Unable to validate the following destination configurations (Service: Amazon S3; Status Code: 400; Error Code: InvalidArgument; Request ID: BDAD922E1C8F9AF8; S3 Extended Request ID: OveJPtub1t7kBmokwpQuoRNoBWT2qTtwf671Pi2jVQU5cKcm2mLyzN4XF76oU6EcSc0Gb74MmQU=).

Serverless.yml:

Function:

contentCreate:
    handler: src/controllers/content.create

S3 Bucket and Lambda Permission:

  S3BucketContent:
    Type: AWS::S3::Bucket
    DependsOn: ContentCreateLambdaPermissionContentS3
    Properties:
      BucketName: ${self:custom.content_bucket}
      CorsConfiguration:
        CorsRules:
          -
            AllowedOrigins:
            - '*'
            AllowedHeaders:
            - '*'
            AllowedMethods:
            - GET
            - PUT
      NotificationConfiguration:
        LambdaConfigurations:
          - Event: s3:ObjectCreated:*
            Function:
              Fn::GetAtt:
              - ContentCreateLambdaFunction
              - Arn
  ContentCreateLambdaPermissionContentS3:
    Type: AWS::Lambda::Permission
    DependsOn: ContentCreateLambdaFunction
    Properties:
      FunctionName:
        Fn::GetAtt:
        - ContentCreateLambdaFunction
        - Arn
      Principal: s3.amazonaws.com
      Action: lambda:InvokeFunction
      SourceAccount:
        Ref: AWS::AccountId
      SourceArn: arn:aws:s3:::{$self:custom.content_bucket}
2 Likes

Did you ever find a resolution to this issue. I’m receiving a similar error and am having a pretty difficult time finding the source. See this stack overflow post.

Anybody has solution to this yet, I am having same error for a cloudformation created bucket, the solution in this link does not seem to work.