Created
May 16, 2018 19:04
-
-
Save cdechery/992ad242e2a7491e27100fb4baa1bd59 to your computer and use it in GitHub Desktop.
Retreive Beanstalk Application name from within EC2 instance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
packages: | |
yum: | |
jq: [] | |
container_commands: | |
01-getenv-info: | |
command: | | |
ENV_ID=`{"Ref": "AWSEBEnvironmentId" }` | |
ENV_NAME=`{"Ref": "AWSEBEnvironmentName" }` | |
echo "env.id="$ENV_ID > /tmp/awseb.properties | |
echo "env.name="$ENV_NAME >> /tmp/awseb.properties | |
EC2_REGION=`curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone | sed 's/[a-z]$//'` | |
APP_NAME=`aws elasticbeanstalk describe-environments --environment-ids $ENV_ID --region=$EC2_REGION | jq -r '.Environments[0].ApplicationName'` | |
echo "app.name="$APP_NAME >> /tmp/awseb.properties | |
chmod 644 /tmp/awseb.properties |
I know it doesn't make it /much/ less ugly but you can avoid installing jq
if you use the --query
flag in the AWS CLI which essentially does the same thing as jq
(just remove the leading dot I think for this case). Otherwise this is super useful, thanks!
Is there a permission requirement here?
describe-environments seems to return an empty array..
Is there a permission requirement here?
describe-environments seems to return an empty array..
I had the same problem and adding AWSElasticBeanstalkReadOnlyAccess
permission to the user fixed the problem. Something more restrictive would probably be better
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I know this solution is SUPER ugly, but it works. It took me hours of searching online for the various pieces that composed this horrible piece of code, that in the end produces the file with all the info I need.