How to set Environment Variables on EC2 instance via User Data

前端 未结 9 747
北荒
北荒 2020-12-14 07:34

I am trying to set environment variables with EC2s user data, but nothing i do seems to work

here are the User data scripts i tried

#!/b         


        
9条回答
  •  长情又很酷
    2020-12-14 08:35

    The user data script on EC2 executes at after boot in its own process. The environment variables get set in that process and disappear when the process exits. You will not see the environment variables in other processes, i.e., login shell or other programs for that matter.

    You will have to devise a way to get these environment variables into whatever program needs to see them.

    Where do you need these variables to be available? In /startup.sh staging 2649?

    EDIT

    Try this:

    #!/bin/bash
    set -e -x 
    export HOST_URL="checkEmai-LoadBala-ICHJ82KG5C7P-2141709021.us-east-1.elb.amazonaws.com"
    /startup.sh staging 2649
    

    Then edit /startup.sh, and put the following line on the top:

    echo $HOST_URL > /tmp/var
    

    Boot the instance, and then paste /tmp/var here.

提交回复
热议问题