Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[aws codebuild] dotenv is not working #65

Closed
ghost opened this issue Jul 31, 2020 · 2 comments
Closed

[aws codebuild] dotenv is not working #65

ghost opened this issue Jul 31, 2020 · 2 comments
Labels
not a bug Does not seem to be a bug with this plugin. question

Comments

@ghost
Copy link

ghost commented Jul 31, 2020

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.

@neverendingqs
Copy link
Owner

neverendingqs commented Feb 6, 2021

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.

@neverendingqs
Copy link
Owner

Please feel free to reopen this issue if you have any more concerns. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not a bug Does not seem to be a bug with this plugin. question
Projects
None yet
Development

No branches or pull requests

1 participant