If you are using linux or mac os for your ec2 instance then, go to your root directory and run the following command:
vim .bash_profile
You will see your bash_profile file open in the text editor 'vim'. Next press 'i' to enter 'insert' mode (or 'o' to enter insert mode on a new line), then append the following:
export DB_PORT="5432"
After adding this line, you need to save the file. So press the 'Esc' key to exit insert mode, then press ':' to initiate a new command, and after colon write 'w' and then press enter to save the file. It will save the file without exiting. To exit, again press ':' after that write 'quit' and the file will close. Alternatively, you can enter 'x' instead of 'w' to save and close the file all at once.
refer here for a vim cheat sheet.
After that run the command, "source ~/.bash_profile" in your shell.
To check that your environment variable is set, enter the below commands in your shell to check via python:
python
>>>import os
>>>os.environ.get('DB_PORT')
>>>5432
or the following in your shell to check natively:
echo DB_PORT