serverless-plugin-ifelse icon indicating copy to clipboard operation
serverless-plugin-ifelse copied to clipboard

Excluding lambda events breaks serverless since serverless 1.52

Open Jaystified opened this issue 5 years ago • 5 comments

For example, for a serverless.yml similar to this:

service: "test"
provider:
  stage: "${opt:stage}"
  name: "aws"
functions:
  foo:
    handler: "handler.foo"
    events:
      - sns: "bar"
plugins:
- "serverless-plugin-ifelse"
custom:
  serverlessIfElse:
    - If: '"${opt:stage}" == "dev"'
      Exclude:
        - "functions.foo.events"

The above worked until serverless 1.52.0 (excluding). After the 1.52.0 release it outputs the following when trying to use the following: TypeError: Cannot read property 'find' of undefined Manually setting foo to have no events still allows packaging and deploying successfully, so I suspect this is a plugin bug.

Jaystified avatar Sep 26 '19 06:09 Jaystified

This issue will be fixed on serverless framework side via https://github.com/serverless/serverless/pull/7932

exoego avatar Jul 12 '20 05:07 exoego

@exoego the issue was closed so it seems this issue is still valid

cscetbon avatar Nov 13 '20 18:11 cscetbon

I also noticed that if I remove the first and only element I get a similar issue (I suppose)

  serverlessIfElse:
    - If: '"${self:provider.stage}" != "prod"'
      Exclude:
        - functions.f1.events.0

sls package --stage dev ... TypeError: Cannot read property 'cloudFront' of undefined

But if I remove it by using its name then it works as expected. It's really confusing

  serverlessIfElse:
    - If: '"${self:provider.stage}" != "prod"'
      Exclude:
        - functions.f1.events.0.sqs

I would expect all of them to work the same when I have only one event. What do you think @exoego ?

  serverlessIfElse:
    - If: '"${self:provider.stage}" != "prod"'
      Exclude:
        - functions.f1.events.0.sqs
        - functions.f1.events.0
        - functions.f1.events

cscetbon avatar Nov 13 '20 18:11 cscetbon

I noticed that after ignore some events of functions using

Exclude:
  - functions.f1.events.1
  - functions.f1.events.2

the events array in serverless library will be like this: events: [ { http: [Object] }, <2 empty items> ], the empty items might cause the 'undefined error'?

SUCHMOKUO avatar Dec 29 '20 05:12 SUCHMOKUO

For example, for a serverless.yml similar to this:

service: "test"
provider:
  stage: "${opt:stage}"
  name: "aws"
functions:
  foo:
    handler: "handler.foo"
    events:
      - sns: "bar"
plugins:
- "serverless-plugin-ifelse"
custom:
  serverlessIfElse:
    - If: '"${opt:stage}" == "dev"'
      Exclude:
        - "functions.foo.events"

The above worked until serverless 1.52.0 (excluding). After the 1.52.0 release it outputs the following when trying to use the following: TypeError: Cannot read property 'find' of undefined Manually setting foo to have no events still allows packaging and deploying successfully, so I suspect this is a plugin bug.

The reply may be late, but might help others. Serverless breaks when event is removed. Try:

custom: serverlessIfElse: - If: '"${opt:stage}" == "dev"' set: functions.foo.events = []

anantab avatar Aug 02 '22 23:08 anantab