Search code examples
amazon-web-servicesamazon-ec2debianenvironment-variables

How to set an environment variable in Amazon EC2


I created a tag on the AWS console for one of my EC2 instances.

enter image description here

However, when I look on the server, no such environment variable is set.

The same thing works with elastic beanstalk. env shows the tags I created on the console.

$ env
 [...]
 DB_PORT=5432

How can I set environment variables in Amazon EC2?


Solution

  • 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