serverless offers a nice workflow for using variables in both the runtime function code as well as in the AWS configuration of Lambda functions and API Gateway routing. This is described at http://docs.serverless.com/docs/templates-variables and How to define variables in a DRY way.
I am having trouble figuring out how to assign variables when I am testing my Lambda functions locally using sls function run -s stage. The function runs fine when I run the test on Lambda by including the -d option, but it fails without it because a necessary variable hasn't been assigned. serverless provides these messages:
Serverless: WARNING: This variable is not defined: region
Serverless: WARNING: This variable is not defined: appEnv
I am using DRY variables as described in link 2. Specifically:
s-variables-aguldman-useast1.json:
{
"appEnv": "qa"
}
functions/fn1/s-function.json:
{
...
"environment": {
"NODE_ENV": "${appEnv}"
}
...
}
functions/fn1/handler.js:
...
var foo = process.env.NODE_ENV;
...
Any advice?
Thanks!