Skip to content

Instantly share code, notes, and snippets.

@onahirniak
Last active May 21, 2020 12:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onahirniak/849bf40a6a995a75723dbe740491d71e to your computer and use it in GitHub Desktop.
Save onahirniak/849bf40a6a995a75723dbe740491d71e to your computer and use it in GitHub Desktop.
Easy ECS deploy
#Login to ECR with AWS SDK v1
#$(aws ecr get-login --no-include-email)
#Login to ECR with AWS SDK v2
aws ecr get-login-password \
| docker login \
--password-stdin \
--username AWS \
"xxx.dkr.ecr.us-west-2.amazonaws.com"
#Build, tag and push to ECR
IMAGE_NAME="name"
docker build -t ${IMAGE_NAME} .
docker tag ${IMAGE_NAME}:latest xxx.dkr.ecr.us-west-2.amazonaws.com/${IMAGE_NAME}:latest
docker push xxx.dkr.ecr.us-west-2.amazonaws.com/${IMAGE_NAME}:latest
#Deploy service
TASK_DEFINITION="name-of-task-definition"
CLUSTER_NAME="cluster-name"
SERVICE_NAME="service-name"
CONTAINER_DEFINITION=$(aws ecs describe-task-definition --task-definition $TASK_DEFINITION | jq .taskDefinition.containerDefinitions)
TASK_VERSION=$(aws ecs register-task-definition --family $TASK_DEFINITION --container-definitions "$CONTAINER_DEFINITION" | jq --raw-output '.taskDefinition.revision')
DEPLOYED_SERVICE=$(aws ecs update-service --cluster $CLUSTER_NAME --service $SERVICE_NAME --task-definition $TASK_DEFINITION:$TASK_VERSION | jq --raw-output '.service.serviceName')
echo "Deployment of $DEPLOYED_SERVICE complete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment