Open Jaystified opened 5 years ago
This issue will be fixed on serverless framework side via https://github.com/serverless/serverless/pull/7932
@exoego the issue was closed so it seems this issue is still valid
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
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'?
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:
For example, for a serverless.yml similar to this:
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.