Explore Courses Blog Tutorials Interview Questions
0 votes
in AWS by (19.1k points)

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


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



How can I set environment variables in Amazon EC2?

1 Answer

0 votes
by (44.4k points)

First, you have to retrieve information from the metadata and later you will be able to run your own set of environment commands.

So first, run this curl statement.


Then you can call the describe-tags using the pre-installed AWS CLI (or install it on your AMI) You can call describe-tags using your AWS CLI and if not pre-installed, install it.

aws ec2 describe-tags --filters "Name=resource-id,Values=i-5f4e3d2a" "Name=Value,Values=DB_PORT"

After this, you can use the Operating System’s set environment variable command.

export DB_PORT=/what/you/retrieved/from/the/previous/call

You can also check out this shell script which was written with the above instructions.

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer

Browse Categories