Reputation: 711
Is there a way to use serverless env variable in s-resources-cf.json?
I create a RDS instance in s-resources-cf.json that's used by some of my lambdas. Instead of putting the db name and password into s-project.json or s-variables-env.json I’d like to reference env vars and have them filled in as part of the deployment, similar to how vars in s-variables-env.json can be references in s-resources-cf.json using ${}.
Upvotes: 3
Views: 1537
Reputation: 3496
You can put the ${rdsInstanceName} in the environment section of a function's s-function.json
file, then access it using the process.env.MyRdsInstanceName
within Lambda:
"environment": {
"MyRdsInstanceName": "${rdsInstanceName}"
...
}
and reference this stage/region specific variable in your Lambda using something like:
var myRdsInstanceName = process.env.MyRdsInstanceName;
Hope this helps
Upvotes: 3