Unable to deploy Lambda with S3 trigger

Issue

When trying to deploy a Lambda function with an S3 trigge, the deployment reports an error and the lambda is created without the desired trigger

Environment

  • Operational System: macOS Catalina
  • Node version: v10.16.3
  • Framework Core: 1.79.0
  • Plugin: 3.7.1
  • SDK: 2.3.1
  • Components: 2.34.6

*No plugins installed

YML with Lambda definition

name: nu-kami-${self:provider.stage}-invalidateCache
handler: dist/invalidateCache.default
description: Invalidates CloudFront cache once the json file with the banner communication is published
timeout: 5
memorySize: 128
vpc: ${self:custom.vpc}
tags:
  functionName: invalidateCache

environment:
  AWS_ACCOUNT_ID: ${self:custom.awsAccountId}
  STAGE: ${self:provider.stage}
  FUNCTION_NAME: invalidateCache
  STATSD_HOST: ${self:custom.statsdHost}
  STATSD_PORT: ${self:custom.statsdPort}
  LOGSTASH_HOST: ${self:custom.logstashHost}
  LOGSTASH_PORT: ${self:custom.logstashPort}
  LOGSTASH_NAME: ${self:custom.logstashName}
  CLOUDFRONT_ID: ${self:custom.cloudfrontId}

events:
  - s3:
    bucket: nu-preprod
    event: s3:ObjectCreated:*
    rules:
      - prefix: banner/
    existing: true

Deployment error

$ serverless deploy --stage preprod --verbose
Serverless: Configuration warning:
Serverless:   at 'functions.invalidateCache.events[0]': unrecognized property 'bucket'
Serverless:   at 'functions.invalidateCache.events[0]': unrecognized property 'event'
Serverless:   at 'functions.invalidateCache.events[0]': unrecognized property 'rules'
Serverless:   at 'functions.invalidateCache.events[0]': unrecognized property 'existing'
Serverless:
Serverless: If you prefer to not continue ensure "configValidationMode: error" in your config
Serverless: If errors are influenced by an external plugin, enquiry at plugin repository so schema extensions are added (https://www.serverless.com/framework/docs/providers/aws/guide/plugins#extending-validation-schema)
Serverless: If errors seem invalid, please report at https://github.com/serverless/serverless/issues/new?template=bug_report.md
Serverless: If you find this functionality problematic, you may turn it off with "configValidationMode: off" setting
Serverless:
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service nu-kami.zip file to S3 (1.25 MB)...
Serverless: Validating template...
Serverless: Updating Stack...
...

Although the serverless version I’m using is updated and the function trigger is as stated in the documentation, I’m having this error during deployment and I don’t know how to proceed.

As you may notice the stack goes on and a deployment is made but no S3 trigger is configured.

2 Likes

The identation of your s3 events configuration is wrong. It should be:

  - s3:
      bucket: nu-preprod
      event: s3:ObjectCreated:*
      rules:
        - prefix: banner/
      existing: true
1 Like

Generally, this error means that your S3 bucket doesn’t have permission to invoke a Lambda function. The required permissions are automatically added to a resource-based policy for your function when you use the Amazon S3 console to configure an event notification for Lambda