Issue
The Problem
I'm dipping my toes into AWS by deploying a simple API built with NestJS. This will be the first app I've deployed to a cloud service. I've already cloned my repository on an AWS Lightsail Linux instance with Node.js and installed all of my dependencies. However, I'm confused on how best to provide environment variables to my app.
Obviously, I has a local .env file that I used during development with credentials for my database, port info, etc. Do I just create a new .env file on the machine running my instance through the command line? I've read that for other AWS services you can provide env variables through that service's UI, but I can't find the same thing for Lightsail.
I would greatly appreciate it if someone could give me an explanation of env variables, and how we should generally provide them to cloud services.
Thank you!
Solution
There could be a better method. But, you could add a file locally on the LightSail server itself. If you don't know how to do so through console, I'll explain below.
- Create the file:
touch .env
- Open up the file in console:
vim .env
. Now you will see the file opened up in console, with weird UI if you haven't seen it before. - Prepare to write to file: press
i
. Now you should see a the~Insert~
mode appear at the bottom. - Add the variables: copy and paste your .env from your local laptop to your lightsail console.
- close out: press
esc
, then type in:wq
, and click onenter
This should work as normal with any .env
file. I'm unsure if there are security issues with this, but I don't believe so.
Answered By - Askar Answer Checked By - Mary Flores (WPSolving Volunteer)