Set Environment Variables in an Aws Instance

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



Leave a reply



Submit