Skip to content

Instantly share code, notes, and snippets.

Last active April 7, 2023 16:11
Star You must be signed in to star a gist
Save yefim/93fb5aa3291b3843353794127804976f to your computer and use it in GitHub Desktop.
Build a Docker image, push it to AWS EC2 Container Registry, then deploy it to AWS Elastic Beanstalk
# usage: ./ staging f0478bd7c2f584b41a49405c91a439ce9d944657
# license: public domain
aws configure set default.region us-east-1
# Authenticate against our Docker registry
eval $(aws ecr get-login)
# Build and push the image
docker build -t $NAME:$VERSION .
docker push $$NAME:$VERSION
# Replace the <AWS_ACCOUNT_ID> with the real ID
# Replace the <NAME> with the real name
sed -i='' "s/<NAME>/$NAME/"
# Replace the <TAG> with the real version number
sed -i='' "s/<TAG>/$VERSION/"
# Zip up the Dockerrun file (feel free to zip up an .ebextensions directory with it)
zip -r $ZIP
aws s3 cp $ZIP s3://$EB_BUCKET/$ZIP
# Create a new application version with the zipped up Dockerrun file
aws elasticbeanstalk create-application-version --application-name $NAME-application \
--version-label $VERSION --source-bundle S3Bucket=$EB_BUCKET,S3Key=$ZIP
# Update the environment to use the new application version
aws elasticbeanstalk update-environment --environment-name $NAME \
--version-label $VERSION
"AWSEBDockerrunVersion": "1",
"Image": {
"Update": "true"
"Ports": [
"ContainerPort": "443"
Copy link

ivarprudnikov commented Nov 25, 2018

sed command contains minor "error":
sed -i='' "s/<AWS_ACCOUNT_ID>/$AWS_ACCOUNT_ID/" will make a backup file called which is not what would be expected. Assume because -i was used the expectation is that file will be modified in place.

-i='' needs to be replaced with either --in-place='' or with -i '' or with a sensible backup extension -i.bak
First 2 options will not work on all systems and I found the last one -i.bak a bit more reliable when running sed on OSX and on Linux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment