1

When launching a AWS EC2 instance, you can give a user data string that is interpreted either as key, value pairs with some configuration variables, or as a bash script, if it begins with a #!/bin/bash line.

We are using a third party software that needs a key, value pair to be given, but also we are configuring the machine at start time using a bash script. I added the key, value pair as an environment variable in the bash script using export KEY=VALUE, but it does not seem to work and arrive to the third party program configuration.

I know that I could give the key, value pairs and then run the bash script using ssh, but it is much harder, as I have to wait the instance to be ready to do it.

Has someone done this successfully?

1 Answer 1

1

Unfortunately, you don't describe which type of Linux that you are using, but bash could be a good starting point. When an EC2 instance is starting, the user data will be executed, and the variable will be available only during that session.

If you want to use ENV variables, you can implement them in .bashrc of the root (or in that user's .bashrc which will run the third party application). If you want system wide ENV variables, you should implement them in /etc/profile or /etc/environment/. Include the variables in your user-data bash script like this: echo KEY=VALUE >> /etc/environment

You can give try to this article/howto also, with more examples.

1
  • I was talking about AWS EC2 user data, and not shell environment variables. User data variables are taken by AWS instance manager as a configuration to do things without having to call to commands directly.
    – cserpell
    Mar 22, 2017 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.