2

I have been using a .env file to run my app in my local machine. However when deploying my app using aws ec2 instance, I am at a complete loss on how to set up the ENV vars as I am a complete beginner at using AWS. Please help me to set up the environment variables.

2
  • 2
    Why not use .env on instance as well? Commented Jan 22, 2021 at 5:39
  • Thanks, it worked. I was thinking too much Commented Jan 22, 2021 at 6:41

1 Answer 1

4

Based on the comments.

Since .env is used on local workstation successfully, it can also be used on ec2 instance.

Just have to be careful with not string any sensitive information in .env and using public repositories, as you may leak your passwords or access keys.

For storing secrets at AWS, the recommended way would be through secret manager or ssm parameter store. Also any permissions that your app may require to access these or other AWS services should be provided through instance role, not by hard codding AWS credentials into app or instance.

Sign up to request clarification or add additional context in comments.

4 Comments

Since the variables defined in the .env should not be committed (are ignored) into the repository, because it's senstive information, there should be some other way to define the environment variables. I am also stuck at this. I found this link and I have added my variables to the bashrc file in the ubuntu server, but I can't find a way so that the app knows how to get them. docs.aws.amazon.com/cloud9/latest/user-guide/env-vars.html
@ivandax You don't store secrets nor any sensitive info there. I think its clear from my answer?
@ivandax the link you provided is handling env-vars specifically in cloud9 (one of AWS services), it's not related to EC2
The Parameter Store is a good route to take.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.