serverless: Environment variables are not resolved same way for remote and local invocations
Bug Report
Description
Given:
environment:
events_store_table:
Ref: EventsStoreEncryptedDynamoDBTable
When invoking a function locally sls invoke local ..., which makes a dynamoDB API call with TableName referencing process.env.events_store_table the following error occurs:
1 validation error detected: Value '[object Object]' at 'tableName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+\
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 15 (11 by maintainers)
how would you solve this:
I have looked at https://github.com/serverless/serverless/pull/8157. How would these changes be used within a
serverless.yamlfile? I am currently using it as this and still getting my env variable set as[object Object]:If there are other’s like me who leverage AWS References, Attributes and ImportValues, I’ve written a workaround for this issue and created a plugin which will resolve AWS resources for aws (currently limited to DynamoDB, Lambda, S3, SNS, SQS, StepFunctions, SecretsManager and Parameter Store).
Here is the GitHub Repo where its been implemented, and instructions on how to install and use the plugin from npm. https://github.com/mutual-of-enumclaw/serverless-plugin-local-env
This plugin overrides the existing implementation of how environment variables are setup for local debugging, and leverage the AWS Stack to resolve values which are requested following the AWS Documentation on CloudFormation for each service.
If there are other services which you need feel free to add them, or let me know as I can add them fairly easily.