2

I am trying to get my lambda to run when an image is added to a "folder" in an s3 bucket. Here is the template

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

When I look at the lambda created on the AWS console, I do not see the trigger even in the lambda visualiser. The lambda doesn't event have the s3 read and write policies attached to it.

The s3 bucket and the lambda are created, but the policies and triggers that are supposed to connect them are not created.

I did not get any error when I run sam deploy

Question: why did it not attach the s3 trigger event or the s3 access policies to the lambda function?

DrkStr
  • 1,752
  • 5
  • 38
  • 90
  • 1
    [policies for s3](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-policy-template-list.html#s3-read-policy) 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](https://github.com/aws/serverless-application-model/issues/300), is that your issue? – lloyd Nov 18 '20 at 07:04
  • Yup, looks like it was an issue with the visualiser. Do you want to post an answer so I can accept it? – DrkStr Nov 18 '20 at 09:42

1 Answers1

1

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, This appears to be your issue. See comments.

lloyd
  • 1,683
  • 2
  • 19
  • 23