CloudFormation macro fails for lambdas unless per-function metadata is specified.
john-tipper opened this issue · comments
Describe the bug
If a template is created with a lambda, the macro function will fail unless the lambda specifically defines a slicWatch
metadata property map.
To Reproduce
Steps to reproduce the behavior:
- Deploy the slicwatch macro manually using CloudFormation.2.
- Create a CloudFormation template with a lambda.
- Deploy the CloudFormation template.
Expected behavior
The stack should deploy without error..
Screenshots, Input Files and Logs
Within the macro lambda logs, you get this:
ERROR Type Error: cannot read properties of undefined (reading 'slicWatch')
at Runtime.exports.handler (/var/task/index.js:59:50)
Environment:
OS: Windows
Node.js Version: 14.17.4
NPM version: 8.3.2
Serverless Framework Version: 1.59.0
Additional context
The error is occurring here: https://github.com/fourTheorem/slic-watch/blob/main/cf-macro/index.js#L59 The problem is that the code is assuming that there is a slicWatch property map associated with the Metadata of each function, whereas this may not exist unless the user has specifically defined that property. The user may just have specified the slicWatch metadata at the top of the template file.
Thanks for spotting this @john-tipper! A fix has been released in version 2.1.1, also released to the Serverless Application Repository.