Search code examples
amazon-web-servicesamazon-s3aws-lambdaaws-samaws-sam-cli

AWS SAM Template: Issue mapping S3 events to Lambda


I've followed the AWS SAM documentation for hands-on learning experience and have reached this particular section: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-s3.html

Above page in the documentation explains how to map the S3 events to any resource and I've done something similar on my local machine. My local template below.

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  CreateThumbnail:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: hello_world/
      Handler: app.lambda_handler
      Runtime: python3.6
      Timeout: 60
      Policies: AWSLambdaExecute
      Events:
        CreateThumbnailEvent:
          Type: S3
          Properties:
            Bucket: !Ref testBucket
            Events: s3:ObjectCreated:*

  testBucket:
    Type: AWS::S3::Bucket

Now, when I build and deploy above SAM template, while a new S3 bucket is getting created, the 'object creation' event is not mapped to the Lambda function created. PSB screenshot.

Screenshot showing that S3 events are not mapped

I haven't found any articles or blogs on this error (probably, I'm doing a silly mistake here)

Please help.

Thanks.


Solution

  • I realized that for some reason, the AWS Lambda console is not showing the trigger event but the mapping is successful. I've also validated by uploading sample image to the bucket which triggered the lambda.

    The event mapping can be seen in the properties section of the S3 bucket created.

    S3 test bucket created -> Properties -> Events

    S3 bucket properties showing the created events