0 votes
1 view
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. ?


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:

[email protected]:~$ echo $foozle


Welcome to Intellipaat Community. Get your technical queries answered by top developers !