Reputation: 144
Created a nodejs lambda function locally and integrated dotenv, so that env variables are accessed using process.env method. It is working. While deploying the same lambda and when tested inside aws console, it is returning undefined for env variable. Any idea why it so.
Upvotes: 3
Views: 5606
Reputation: 21
In my case AWS and Google Cloud Platform not allow us to use some keywords name in the variable environnement like :
not ok : AWS_ACCESS_KEY_ID = "XXXXX"
ok : CLOUD_ACCESS_KEY_ID = "XXXXX"
not ok : AWS_SECRET_ACCESS_KEY = "XXX"
ok CLOUD_SECRET_ACCESS_KEY = "XXX"
Upvotes: 0
Reputation: 797
In case it helps: you need to specify the environment variable in lambda function section of the template.yaml
file as well. Example:
requestRetrievalFunction:
...
Properties:
...
Environment:
Variables:
EMAILS_TABLE: !Ref EmailsTable
TIME_TO_EXPIRE: 20
...
In my particular case I am using two env variables (EMAILS_TABLE
and TIME_TO_EXPIRE
). For local testing I defined them in the env.json
file too:
{
"requestRetrievalFunction": {
"EMAILS_TABLE": "nico-ppot",
"TIME_TO_EXPIRE": 30
}
}
Upvotes: 0
Reputation: 386
You have to mention in Environment variables at Lambda.
either if you are using server-less template to deploy , mentioned under 'Environment'
# serverless.yml
provider:
name: aws
runtime: nodejs4.3
environment:
envOne: 12345678
functions:
myFunction:
environment:
envTwo: 87654321
Reference : https://www.serverless.com/blog/serverless-v1.2.0
https://www.serverless.com/framework/docs/providers/aws/guide/variables/
Upvotes: 0
Reputation: 4215
Download your deployment zip file from S3 and make sure it has the .env
file.
Upvotes: 1