Env is not passed to Lambda funtion.
Description:
Steps to reproduce the issue:
sam init -r nodejs8.10 to generate template.yaml with the following in it:Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: hello_world/
Handler: app.lambda_handler
Runtime: nodejs8.10
Environment:
Variables:
PARAM1: VALUE
Events:
HelloWorld:
Type: Api
Path: /hello
Method: get
exports.lambda_handler = async (event, context, callback) => {
callback(null, {
'statusCode': 200,
'body': JSON.stringify(process.env)
})
};
{
"HelloWorldFunction":{
"MY_TEST_ENV_PROP": "value"
}
}
MY_OTHER_TEST_ENV_PROP="OTHER_VALUE" sam local start-api --debug --port 8000 --env-vars env.json
Observed result:
No MY_TEST_ENV_PROP and MY_OTHER_TEST_ENV_PROP listed. However the PARAM1 from the template.yaml - is.
Expected result:
process.env.MY_TEST_ENV_PROP and process.env.MY_OTHER_TEST_ENV_PROP should exist and be equal to appropriate values as described in https://docs.aws.amazon.com/lambda/latest/dg/test-sam-cli.html
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
Mac,
Python 2.7.10
Output of sam --version:
$ sam --version
SAM CLI, version 0.4.0
@milashenko I think the document may be misleading. The shell and file vars you can define when running the cli only override the ones already declared in your template file. Only PARAM1 in your example then.
Most helpful comment
@milashenko I think the document may be misleading. The shell and file vars you can define when running the cli only override the ones already declared in your template file. Only PARAM1 in your example then.