Reputation: 9750
I am deploying my code to AWS EC2. The documentation says there's something called "user data" or "user data scripts" that you can enter this info when you're launching an ec2 instance and the script will be executed at instance startup.
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html#user-data-shell-scripts
the following is in my user data script:
#!/bin/bash
echo 1111 >> /home/ubuntu/1111.txt
export MONGODB_HOST=www.mongodb.com
export MONGODB_PORT=12345
export MONGODB_USER=user
export MONGODB_PASS=pass
So when I launch the instance with this user data script I would expect to see the environment variables being set, but it didn't.
So is there something that I did wrong?
Upvotes: 4
Views: 10619
Reputation: 871
Your user data script is actually run. Nevertheless, it is run on its own bash process which dies at the end of your script.
Exported variables are preserved only for the lifetime of your script and they are also visible from child processes of your script.
Since new connections to your ec2 instance are not children of the original script that ran the user data, they don't inherit exported variables.
Upvotes: 6