AWS S3 with event: Unable to validate the following destination configurations

Hi,

when i deploy my image resizing code with:
sls deploy --stage acc --bucket mybucketname --verbose

I get:
CloudFormation - CREATE_FAILED - Custom::S3 - ImageResizeCustomS31

An error occurred: ImageResizeCustomS31 - Failed to create resource. Unable to validate the following destination configurations

This is my serverless.yml

service: myproject-image-service
custom:
  uploadFolder: uploads/

provider:
  name: aws
  runtime: nodejs10.x
  region: eu-west-1
  iamRoleStatements:
    - Effect: Allow
      Action:
        - s3:*
      Resource: 'arn:aws:s3:::${opt:bucket}/*'

functions:
  imageResize:
    handler: resizeImageHandler.resize
    environment:
      BUCKET: ${opt:bucket}
      UPLOAD_FOLDER: ${self:custom.uploadFolder}
    events:
      - s3:
          bucket: ${opt:bucket}
          event: s3:ObjectCreated:*
          existing: true
          rules:
            - prefix: ${self:custom.uploadFolder}`

Note: when i remove the events part, it works. Seems to be a timing issue? but how do i solve this?

1 Like

Ay,

I got the same error with my S3 events block.

Did you find a solution ?

EDIT : I found the solution in Github. You need to delete your events and recreate them. I did that and now it works fine. I hope it can help. :slight_smile:

Here is my code :

service: ultima-api
# app and org for use with dashboard.serverless.com
app: ultima-api
org: xxx

# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
# frameworkVersion: "=X.X.X"

provider:
  name: aws
  runtime: nodejs12.x
  stage: ${opt:stage, 'dev'}
  region: us-east-1

  memorySize: 512
  timeout: 180

  iamManagedPolicies:
    - "arn:aws:iam::xxx:policy/BcnUltima"

  environment:
    TEST: ${self:custom.${self:provider.stage}.s3-temp-bucket}

functions:
  onS3UnzipToS3:
    handler: src/handler.onS3UnzipToS3
    events:
      - s3:
          bucket: ${self:custom.${self:provider.stage}.s3-temp-bucket}
          existing: true

plugins:
  - serverless-plugin-typescript
  - serverless-offline

custom:
  prod:
    s3-temp-bucket: mybucket-prod
  dev:
    s3-temp-bucket: mybucket-dev

Nice, it works!

In case anybody doesn’t know how to delete S3 events, please jump to https://docs.aws.amazon.com/AmazonS3/latest/user-guide/enable-event-notifications.html for details.

2 Likes