How to set an environment variable in Amazon EC2
Following the instructions given by Guy, I wrote a small shell script. This script uses AWS CLI and jq
. It lets you import your AWS instance and AMI tags as shell environment variables.
I hope it can help a few people.
https://github.com/12moons/ec2-tags-env
Set environment variables in an AWS instance
Using the export command only sets those variables for the current shell and all processes that start from that shell. It is not a persistent setting. Anything you wish to make permanent should be set in /etc/environment
.
For example in userdata:
echo "JAVA_HOME=/jdk1.8.0_172" >> /etc/environment
This would add the JAVA_HOME=/jdk1.8.0_172
line to that file. Note, you should not use export
inside that file.
The PATH
variable is likely already defined in the /etc/environment
file and you'll need to overwrite that appropriately if you are going to append additional paths to it.
There is really great details on setting environment variables available in this answer.
How to set env variables for react & go in aws ec2
I use elastic beanstalk and set environment variables there.
How to store environment variables on AWS EC2?
The best secure way is to use AWS system Manager
Rerference:
https://aws.amazon.com/blogs/mt/use-parameter-store-to-securely-access-secrets-and-config-data-in-aws-codedeploy/
Its secure and fully compatible with codedeploy
Related Topics
What Is The Meaning of This Macro _Ior(My_Macig, 0, Int)
Why I Am Not Getting Signal Sigkill on Kill -9 Command in Bash
Cannot Change The Maximum Open Files Per Process with Sysctl
How to Build The Elf Interpreter (Ld-Linux.So.2/Ld-2.17.So) as Static Library
"Invalid Arithmetic Operator" in Shell
How Are Interrupts Handled on Smp
How to Answer Yes in Bash Script
Trying to Launch an External Editor from Within a Go Program
What Determines The Order Directory Entries Are Returned by Getdents
Linux: How to Put a Load on System Memory
How to Add Export Statement in a Bash_Profile File
How to Redirect Http to Https Using Gcp Load Balancer
Docker Run Hello-World Still Fails, Permission Denied
Execute a Script After Every Git Push
Udev Rule with Few Parent Device Attributes