How to set Environment Variables on EC2 instance via User Data

前端 未结 9 744
北荒
北荒 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 08:16

    I find this to be a pretty easy way to set environment variables for all users using User Data. It allows me to configure applications so the same AMI can work with multiple scenarios:

    #!/bin/bash
    echo export DB_CONNECTION="some DB connection" >> /etc/profile
    echo export DB_USERNAME="my user" >> /etc/profile
    echo export DB_PASSWORD="my password" >> /etc/profile
    

    Now, all users will have DB_CONNECTION, DB_USERNAME and DB_PASSWORD set as environment variables.

提交回复
热议问题