Auto-generate your dotenv configuration from serverless framework exports.
Use yarn to either:
# Install into local package.json
yarn add https://github.com/cdaloisio/serverless-dotenv --dev
# Install globally
yarn global add https://github.com/cdaloisio/serverless-dotenv
# Run via npx without installation
npx https://github.com/cdaloisio/serverless-dotenv
Create an envMap.yml
file in your project that maps environment variables to the export names in your serverless stack. You can interpolate the stage value in these export names.
Example:
USER_UPLOADS_S3_BUCKET: myapp-${stage}-user-uploads-bucket
COGNITO_USER_POOL: myapp-${stage}-cognito-user-pool
Run serverless-dotenv with the required options.
npx https://github.com/cdaloisio/serverless-dotenv --stage {stage} --profile {profile} --region {region}
It will create a dotenv
file suffixed with the stage which you can then use in your application build.
USER_UPLOADS_S3_BUCKET: some-s3-bucket-name
COGNITO_USER_POOL: some-cognito-user-pool-arn
--stage The stage you have provided for your serverless deploy. [string] [required]
--profile Your AWS profile as stored in your AWS credentials. [string] [required]
--region The AWS region that you are deploying to. [string] [required]
--envMapFile This file should contain the mapping for ENV variables to CloudFormation exports that you wish to use. [string] [default: "envMap.yml"]
--version Show version number [boolean]
--help Show help [boolean]
Generated using TypeDoc