How can you get the Elastic Beanstalk Application

2019-06-15 13:39发布

We want to be able to retrieve the elastic beanstalk application version in our PHP code. I don't see that EB passes it to us in any server configuration files, which I find it strange. Does anyone else know how we might be able to get this?

7条回答
干净又极端
2楼-- · 2019-06-15 13:59

In PHP application, you can get it using

aws elasticbeanstalk describe-environments --environment-names <environment-name>

You should add the below environment variables in the php script to get it working.

AWS_DEFAULT_REGION AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY

I have used putenv() function to set the environment variables and shell_exec() to get the json output. Parsed the json output to get the VersionLabel which is the actual application version.

查看更多
beautiful°
3楼-- · 2019-06-15 14:01

While the best way is really to ask AWS directly:

aws elasticbeanstalk describe-environments  | \
    jq -r '.Environments | .[] | .EnvironmentName + " " + .VersionLabel'

I've had limited success deducing the same 4 or 5 digit hash by using:

git rev-parse --short=4 $(git log -1 --pretty=format:%h)
查看更多
淡お忘
4楼-- · 2019-06-15 14:04

tail /var/log/eb-activity.log | grep -i "\[Application update .*\] : Completed activity." | tail -1 | sed -E 's/.*Application update (.*)@.*/\1/'

Outputs the actual app version ID like app-2.15.0-31-gf4a2918 in our case.

This works from inside any EB EC2, requires no API hit or git repo (some deploy by zip). Useful for sending a notification about a recent deployment.

查看更多
干净又极端
5楼-- · 2019-06-15 14:17

Consolidating on the answers from @Georgij and @IanBlenke here are the ways you can find the version.

1. Most Reliable (Manifest)

You can sudo cat /opt/elasticbeanstalk/deploy/manifest

Output:

{"RuntimeSources":{"PLATFORM_NAME":{"app-ae22-190115_152512":{"s3url":""}}},"DeploymentId":45,"Serial":53}

2. You can look at the eb-activity logs

Secondly you could look at the eb-activity logs. This will only show you in the log line... You have to assume it's been a successful installation too..

tail /var/log/eb-activity.log | grep -i "app-.*@"

enter image description here

查看更多
▲ chillily
6楼-- · 2019-06-15 14:18

At least for Docker containers - you can use the information stored in /opt/elasticbeanstalk/deploy/manifest.

查看更多
劫难
7楼-- · 2019-06-15 14:18

I've just been looking for a solution myself.

For now, at least, the following works:

unzip -z "${EB_CONFIG_SOURCE_BUNDLE}" | tail -n1

To elaborate,$EB_CONFIG_SOURCE_BUNDLE contains a path to the zip archive of your application (i.e. /opt/elasticbeanstalk/deploy/appsource/source_bundle). The version tag is embedded as a comment in this file.

查看更多
登录 后发表回答