Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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