serverless: Breaking change in 1.28.0: Environment variable ... must contain string
This is a Bug Report
Description
After updating today to 1.28.0, Serverless (or a dependency) now expects all environment variables to be strings. This sounds reasonable, but it’s a breaking change so I’m making people aware.
In YAML, if a string is unquoted then it gets interpreted as a number if it only contains digits. E.g.
AWS_ACCOUNT_ID: 1234567890
is different to
AWS_ACCOUNT_ID: '1234567890'
Our CI pipeline uses YamlDotNet to generate the Yaml which contains the environment variables. This has an open issue where it cannot serialize numeric strings properly.
Running serverless deploy now gives
Serverless: Packaging service...
Serverless Error ---------------------------------------
Environment variable AWS_ACCOUNT_ID must contain string
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Your Environment Information -----------------------------
OS: win32
Node Version: 9.11.1
Serverless Version: 1.28.0
Working around for us is not trivial. If it’s easy for Serverless to resolve this breaking change, it may help others. I’ve solved this for now by fixing Serverless version to 1.27.1
Similar or dependent issues:
Additional Data
- 1.28.0:
- win64:
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 52
- Comments: 31 (7 by maintainers)
this obviously applies to empty vars too. we use SSM to populate envars and sometimes want that var to be empty +1
Hey all, we just released v1.29.2 patch that includes a fix for this. Thanks to everyone for reporting, and special thanks to @horike37 for the fix! 😊
@serverless/framework-maintainers I have fixed this on #5166. Please review it.
I’m getting this with v1.29.2. It only happens on package or deploy, but works great when debugging with offline.
serverless.yml:
environment: ${file(config/env.yml):${self:provider.stage,'local'}}…arn: ${self:provider.environment.events.crm.my_event}env.yml:
event-names-local.yml:
Error message when trying to deploy:
This bug was unintentionally introduced by #4890. My possible solution to the problem is here
sls deploy. This cause the breaking.sls deploy functionWe should cut a patch release as soon as possible.
cc: @serverless/framework-maintainers
Same here… fourthed?
@timgivois I 100% agree the breaking change is in Serverless, and I would even go so far as to say it shouldn’t even be a warning and should quietly coerce all primitive types to a string.
@jamesdixon that doesn’t sound right to me. These values should be read from
process.envwhich always returns a string from what I can tell. Thus I would expect those libraries to coerce the string values into the required type.However, I still think having a breaking change in 1.28 is not ideal!
I’m having this issue too. I had to downgrade:
Don’t forget
null,true,false, and any other non-number & non-string field types.+1 (also thumbed up 👍 the initial comment). We had multiple pipelines begin failing late last week, and traced it back to this breaking update. May make us rethink our pinning serverless versus vs. leading latest, but hoping 1.28.1 is coming soon. Also wonder regarding any future alignment to semver versioning for the package? We’d love to understand when breaking changes are coming (2.x) to make a decision, and let us pin to 1.x for all backward-compat feature enhancements, security patches, etc.
+1, Thanks!
Thirded.
This also happens during
sls packagenot justsls deploy.@horike37 Agree. We should put that into 1.28.1. I will create a patch branch and cherry pick as soon as a solution is ready.
Is this enough, or do we have to cover cases where an env var is set to an object too?