Skip to content

Instantly share code, notes, and snippets.

@fabsrc
Last active September 5, 2017 15:58
Show Gist options
  • Save fabsrc/a220d33b3f59a073b409c325dbdd29af to your computer and use it in GitHub Desktop.
Save fabsrc/a220d33b3f59a073b409c325dbdd29af to your computer and use it in GitHub Desktop.
Package and upload ElasticBeanstalk application to AWS
AWS_DEFAULT_REGION=__AWS_region__
APPLICATION_NAME=__EB_application_name__
ENVIRONMENT_NAME=__EB_environment_name__
VERSION_NAME=__EB_version_name__
FILENAME=$APPLICATION_NAME-$VERSION_NAME.zip
BUCKET=__S3_bucket_name__
# AWS_PROFILE=__AWS_local_profile__
AWS_ACCESS_KEY_ID=__AWS_access_key_id__
AWS_SECRET_ACCESS_KEY__AWS_secret_access_key__
set +x
# check if application version already exists
CHECK_VERSION=$(aws elasticbeanstalk describe-application-versions \
--region $AWS_DEFAULT_REGION \
--application-name $APPLICATION_NAME \
--version-labels $VERSION_NAME \
--query "ApplicationVersions[0].VersionLabel" \
)
if [ "$CHECK_VERSION" == "null" ]; then
# create artifact
git archive --format=zip HEAD > $FILENAME
# copy artifact to S3 bucket
aws s3 cp $FILENAME s3://$BUCKET/$APPLICATION_NAME/$FILENAME --region $AWS_DEFAULT_REGION
# create elastic beanstalk application version with artifact from S3 bucket
echo "Creating application version $VERSION_NAME"
aws elasticbeanstalk create-application-version \
--region $AWS_DEFAULT_REGION \
--application-name $APPLICATION_NAME \
--version-label $VERSION_NAME \
--description "Last commit $REVISION"\
--source-bundle S3Bucket=$BUCKET,S3Key=$APPLICATION_NAME/$FILENAME
else
echo "Application version $VERSION_NAME already exists. Aborting upload..."
exit 1
fi
set -x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment