Environment variables using AWS CodeDeploy

心已入冬 提交于 2019-12-03 09:49:20

One way I have found to set environment variables is through scripts run during the AfterInstall hook (specified in the appspec http://docs.aws.amazon.com/codedeploy/latest/userguide/app-spec-ref.html).

I am able to determine the environment I am currently deploying to in these scripts by calling to my instances metadata where I get my instance id and then utilize the aws cli to execute describe-tags filtered to my instance Id where I have a tag set for Environment

ID=$(curl "http://169.254.169.254/latest/meta-data/instance-id")
aws --region us-east-1 ec2 describe-tags --filters Name=resource-id,Values=$ID Name=key,Values=Environment

I don't love this, but until Code Deploy has something built in to pass parameters to the appspec, this is the best I can find.

Assuming you are using github to manage your code, here is one potential way to manage your environment

Use git-crypt(https://github.com/AGWA/git-crypt) to encrypt sensitive information. You can put the key to decode these files on the server. During codedeploy afterInstall phase, you could decrypt and setup the environment.

The advantage is now you have all the information in one place in a safe way.

It seems to be possible to use Environment Variables (mainly your DEPLOYMENT_GROUP_NAME).

See this guide from Amazon.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!