anantab / serverless-plugin-ifelse

A Serverless Plugin to write If Else conditions in serverless YAML file
69 stars 21 forks source link

Excluding lambda events breaks serverless since serverless 1.52 #11

Open Jaystified opened 5 years ago

Jaystified commented 5 years ago

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.

exoego commented 4 years ago

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

cscetbon commented 4 years ago

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

cscetbon commented 4 years ago

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
SUCHMOKUO commented 3 years ago

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'?

anantab commented 2 years ago

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: