Skip to content

Instantly share code, notes, and snippets.

@quangnhut123
Last active September 23, 2020 01:35
Show Gist options
  • Save quangnhut123/f222ef5a1f4859dd80c0d96515048b8f to your computer and use it in GitHub Desktop.
Save quangnhut123/f222ef5a1f4859dd80c0d96515048b8f to your computer and use it in GitHub Desktop.
#!/bin/bash
while getopts c:s: flag
do
case "${flag}" in
c) cluster_name=${OPTARG};;
s) service_name=${OPTARG};;
esac
done
usage() {
echo "Usage: $0 -c <cluster_name> -s <service_name>"
echo " <cluster_name> must be inputed."
echo " <service_name> must be inputed."
exit 1;
}
if [ -z "$cluster_name" ] || [ -z "$service_name" ]; then
usage
fi
# login ecr repository
$(aws ecr get-login --no-include-email --region ap-northeast-1)
# get latest task definition
latest_task=$(aws ecs describe-services --cluster "${cluster_name}" --service "${service_name}" --query "services[0].taskDefinition" --output text)
# stop all containers before start
ecs-cli local down --all
# start container with task definition
ecs-cli local up --force --task-def-remote $latest_task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment