Note, I prefer the node --require option of loading .env variables over importing or requiring in application code.
- install dotenv as a development dependency
- in the cdk.json in the root of the project directory add the following in bold :
- { "app": "npx ts-node -r dotenv/config --prefer-ts-exts bin/<stack-name>.ts" }
When developing via AWS CDK it is easy to set environment variables on resources as they are being defined to be stored in AWS. However, in some repositories there is a need to set environment variables for the CDK Stack to use.