简体   繁体   中英

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.

显示 S3 事件未映射的屏幕截图

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

Please help.

Thanks.

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 存储桶属性

You can add a AWS::Lambda::Permission to your Resources . That worked for me: https://github.com/awslabs/serverless-application-model/issues/300#issuecomment-510847259

First create bucket where you plan to save packaged code

aws s3 mb s3://youtbucketname

After sam build go for

sam package --template-file template.yaml --s3-bucket <yourbucketname>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM