14

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?

Harry B
  • 2,864
  • 1
  • 24
  • 44
Random5000
  • 1,562
  • 3
  • 16
  • 26
  • AFAIK, when Elastic Beanstalk deploys your application to the cloud, it creates an archive with `git archive` command. The resulting archive file does not have any repository metadata. – kukido Dec 26 '13 at 06:14

8 Answers8

7

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

Georgij
  • 535
  • 1
  • 7
  • 17
4

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.

apancutt
  • 91
  • 1
  • 4
  • 2
    In case anyone stumbles across this, this apparently does not work for Ruby containers. – mentat Jan 17 '14 at 01:30
  • @mentat - does the envvar not exist or is the file missing, or both? It's expected that each lang environment has it's own deployment implementation but I would have thought the process of getting the code onto the server would be consistent.If you find a solution please could you follow up, or contribute to https://github.com/apancutt/aws-eb-newrelic-deploynotify – apancutt Jan 17 '14 at 08:07
  • The envvar exists but it looks like the output is perhaps a hash. I'll take a closer look at the actual file to see where it's embedded. Are you using the aws git to push or something else? – mentat Jan 17 '14 at 20:11
  • 1
    Yes, using git to deploy (aws.push). The hash is the latest git commit which Elastic Beanstalk uses as the version label - at least for PHP applications. – apancutt Jan 18 '14 at 10:00
  • I saw no such environment variable for a node container, so just used hardcoded `/opt/elasticbeanstalk/deploy/appsource/source_bundle` (yuck) – Carl Jun 03 '15 at 21:02
  • 1
    `unzip -z "/opt/elasticbeanstalk/deploy/appsource/source_bundle" | awk 'NR==2 { printf("%.7s\n", $1) }'` is the equivalant to `git rev-parse --short HEAD` – John Morales Dec 18 '15 at 18:52
4

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

Layke
  • 51,422
  • 11
  • 85
  • 111
2

You can use AWS Elastic Beanstalk API to retrieve your application version information.

Describe Application Versions returns descriptions for existing application versions.

Sample request

https://elasticbeanstalk.us-east-1.amazon.com/?ApplicationName=SampleApp
&Operation=DescribeApplicationVersions
&AuthParams 

Sample response

<DescribeApplicationVersionsResponse xmlns="https://elasticbeanstalk.amazonaws.com/docs/2010-12-01/">
  <DescribeApplicationVersionsResult>
    <ApplicationVersions>
      <member>
        <SourceBundle>
          <S3Bucket>amazonaws.com</S3Bucket>
          <S3Key>sample.war</S3Key>
        </SourceBundle>
        <VersionLabel>Version1</VersionLabel>
        <Description>description</Description>
        <ApplicationName>SampleApp</ApplicationName>
        <DateCreated>2010-11-17T03:21:59.161Z</DateCreated>
        <DateUpdated>2010-11-17T03:21:59.161Z</DateUpdated>
      </member>
    </ApplicationVersions>
  </DescribeApplicationVersionsResult>
  <ResponseMetadata>
    <RequestId>773cd80a-f26c-11df-8a78-9f77047e0d0c</RequestId>
  </ResponseMetadata>
</DescribeApplicationVersionsResponse>
kukido
  • 10,431
  • 1
  • 45
  • 52
2

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)
IanBlenke
  • 376
  • 1
  • 5
2

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.

Heath Dutton
  • 4,282
  • 1
  • 13
  • 6
0

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.

KiranD
  • 433
  • 2
  • 7
  • 20
0

On the Python platform, the version details can be found in the EC2 instance:

sudo cat /opt/elasticbeanstalk/deployment/app_version_manifest.json
zakum1
  • 895
  • 6
  • 20