Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in AWS by (12.9k points)

I am using AWS Java API RunInstance() to start a new EC2 instance from my custom AMI image. How do I pass environment variables to the new EC2 INSTANCE such as database url, AWS credentials etc. ?

closed

1 Answer

+1 vote
by (18.2k points)
selected by
 
Best answer

you can try echoing the environment varibales into /etc/environment as shown below:

reservation = connection.run_instances(image_id = image_id,

  key_name = keypair,

  instance_type = 'm1.small',

  security_groups = ['default'],

  user_data = '''#!/bin/sh\necho export foozle=schmoozle >> /etc/environment\n''')

Then, once you have SSH'ed into your instance:

ubuntu@ip-10-190-81-29:~$ echo $foozle

schmoozle

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

...