使用 SAM 向我的 lambda 函数添​​加 s3 事件触发器时遇到问题

Trouble adding an s3 event trigger to my lambda function with SAM

当图像添加到 s3 存储桶中的“文件夹”时,我试图让我的 lambda 达到 运行。这是模板

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: 1. Creates the S# bucket that sotres the images from the camera.\n
             2. Resizes the images when a new image shows up from a camera.\n
             3. Adds a record of the image in the DB.

Globals:
  Function:
    Timeout: 10

Parameters:
  DeploymentStage:
    Type: String
    Default: production

Resources:
  CameraImagesBucket:
    Type: 'AWS::S3::Bucket'
    Properties:
      BucketName: !Sub
        - com.wastack.camera.images.${stage}
        - { stage: !Ref DeploymentStage }

  CreateThumbnailFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: image_resize/
      Handler: app.lambda_handler
      Runtime: python3.8
      Description: Creates a thumbnail of images in the camare_images bucket
      Policies:
        - S3ReadPolicy:
            BucketName: !Sub
              - com.wastack.camera.images.${stage}
              - { stage: !Ref DeploymentStage }
        - S3WritePolicy:
            BucketName: !Sub
              - com.wastack.camera.images.${stage}
              - { stage: !Ref DeploymentStage }
      Events:
        CameraImageEvent:
          Type: S3
          Properties:
            Bucket:
              Ref: CameraImagesBucket
            Events:
              - 's3:ObjectCreated:*'
            Filter:
              S3Key:
                Rules:
                  - Name: prefix
                    Value: camera_images

当我查看在 AWS 控制台上创建的 lambda 时,即使在 lambda 可视化器中也没有看到触发器。 lambda 事件没有附加 s3 读写策略。

已创建 s3 存储桶和 lambda,但未创建应连接它们的策略和触发器。

我在 运行 sam deploy

时没有收到任何错误

问题:为什么没有将 s3 触发事件或 s3 访问策略附加到 lambda 函数?

Policies for s3 So the template is straight forward. If you place the full template in does it work. If that is also failing, check the permissions on what you're running SAM as. Also there's an open ticket on github,这似乎是你的问题。查看评论。