Reputation: 21
A total beginner level question here - I am trying to deploy my mern full stack app to aws ec2 (Amazon Linux 2 ) as a side project for the first time. I was able to get the frontend static React files into the aws ec2 instance. But I am confused as to how to proceed with the backend portion. The backend (nodejs + express) uses a .env file for database connections and such. What would be the safest and/or conventional method to transfer the values in the env file to the instance?
Here are the suggestions I came across and my thoughts on them. Would appreciate some guidance.
Upvotes: 2
Views: 3485
Reputation: 155
Another way could be that you store your .env to secure S3
storage bucket and add shell commands in start_server.sh
for retrieving .env
from S3 and load it with your application to work.
Still, I am not sure if this is the best or most secure way of doing this.
Upvotes: 0
Reputation: 3723
Since you are using .env
file in the existing server, option 2 (storing it as .env
file in EC2) is the direct equivalent. This is a valid and secure design, as long as the file does not contain any secret values.
If your variables do have secrets, this is another problem altogether. The "AWS way" would be SSM Parameter Store or Secrets Manager. I don't see how storing it in user data or .bash_profile
makes it more secure.
Upvotes: 3