Skip to content

Instantly share code, notes, and snippets.

@cdechery
Created May 16, 2018 19:04
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdechery/992ad242e2a7491e27100fb4baa1bd59 to your computer and use it in GitHub Desktop.
Save cdechery/992ad242e2a7491e27100fb4baa1bd59 to your computer and use it in GitHub Desktop.
Retreive Beanstalk Application name from within EC2 instance
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
@FilipDusek
Copy link

FilipDusek commented Apr 28, 2020

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