[aws codebuild] dotenv is not working
SeoHyunDeock opened this issue · 2 comments
I am using serverless and serverless dotenv plugin.
And it is working properly.
But, our team move to aws codepipeline and codebuild for ci/cd.
Our project's ignore .env.* files to push github.
So, using codebuild envrionment variales.
But, it is not working.
I run this command in codebuild
- printenv
And injected environment variables showing.
But node.js process.env has not.
How to inject aws codebuild environment variables to node.js process.env using serverless-dotenv-plugin?
I tried below comman in codebuild
- printenv > .env.production
But, it is not working.
build size is just 4.98MB but, lambda upload size too large error occured.
how to do...?
my setting info
node.js : 10.15
aws buildspec : 0.2
serverless framework with serverless-webpack-plugin and serverless-dotenv-plugin ( with node dotenv npm )
And push my .env files to github, it is working properly.
So, I think that serverless-dotenv-plugin is not using aws codebuild env variables
Thank you.
So, I think that serverless-dotenv-plugin is not using aws codebuild env variables
That sounds correct. It only loads environment variables in dotenv file(s).
Because CodeBuild has already set those environment variables, you can reference then directly via ${env.YOUR_ENV_VAR}
.
This plugin sets provider.environment
for you based on the contents of the dotenv file(s). This explains why they are set on your local environment but not on CodeBuild. #38 (comment) has more details.
I recommend you set the environment variables you need directly like:
provider:
environment:
YOUR_ENV_VAR: ${env:YOUR_ENV_VAR}
OR
functions:
functionOne:
environment:
YOUR_ENV_VAR: ${env:YOUR_ENV_VAR}
to resolve your use case and for security reasons.
Please feel free to reopen this issue if you have any more concerns. Thanks!