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.
1 Answer
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.
4 Comments
ivandax
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.htmlMarcin
@ivandax You don't store secrets nor any sensitive info there. I think its clear from my answer?
Nir Alfasi
@ivandax the link you provided is handling env-vars specifically in cloud9 (one of AWS services), it's not related to EC2
Jon Kern
The Parameter Store is a good route to take.
.envon instance as well?