As already mentioned, it is basically not possible to update the version-label
in Elastic Beanstalk.
But we found a solution which's fine for us. We created a separate stage in the CodePipeline with a Lambda action. The user parameter is #{source_variables.CommitMessage}
and the Input artifact is the build_output
. In the lambda function the incoming event is getting read out for the commit message
def lambda_handler(event, context):
commit_message = event['CodePipeline.job']['data']['actionConfiguration']['configuration']['UserParameters']
In the next step we read out the version from the package.json
from build_output
on s3 bucket
# Read out data from package.json on s3 zip object
with tempfile.TemporaryFile() as f:
s3_resource.meta.client.download_fileobj(s3_bucket_name, s3_object_key, f)
archive = zipfile.ZipFile(f)
package_json = archive.open('package.json')
data = package_json.read()
json_data = json.loads(data)
application_version = json_data['version']
Now the function can update the application version description from the elastic beanstalk environment
# Read out version-label from environemt
environment = eb_client.describe_environments(ApplicationName=application_name)
version_label = environment['Environments'][0]['VersionLabel']
description = 'Version: {} - Commit Message: {}'.format(application_version, commit_message)
# Write new Description to given elastic Beanstalk Application version
eb_response = eb_client.update_application_version(
ApplicationName=application_name,
VersionLabel=version_label,
Description=description
)
Now we can reference our application versions to version and commits. Please keep in mind those are just code snippets and not the whole logic.