How to set Environment Variables on EC2 instance via User Data

前端 未结 9 750
北荒
北荒 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:32

    You can add another shell script in /etc/profile.d/yourscript.sh which will contain the set of environment variables you want to add.

    This script will run at every bootup and your variable will be available to all users.

    #!/bin/sh
    echo 'export AWS_DEFAULT_REGION=ap-southeast-2' > ~/myconfiguration.sh
    chmod +x ~/myconfiguration.sh
    sudo cp ~/myconfiguration.sh /etc/profile.d/myconfiguration.sh
    

    The above code creates a shell script to set environment variable for aws default region and copies it to profile.d .

     

提交回复
热议问题