Skip to content

Instantly share code, notes, and snippets.

@urtens
Created February 4, 2016 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save urtens/91749665274688cb1d80 to your computer and use it in GitHub Desktop.
Save urtens/91749665274688cb1d80 to your computer and use it in GitHub Desktop.
Delete ecs service
#!/bin/bash
set -o pipefail
CLUSTER=$1
SERVICE=$2
echo getting service info
DETAILS=$(aws ecs describe-services --cluster $CLUSTER --services $SERVICE)
echo getting role
ROLE=$(echo "$DETAILS" | jq -r .services[0].roleArn | perl -pe 's{.+/}{}')
echo role: $ROLE
echo getting elb
ELB=$(echo "$DETAILS" | jq -r .services[0].loadBalancers[0].loadBalancerName)
echo elb: $ELB
echo creating role $ROLE
aws iam create-role --role-name $ROLE --assume-role-policy-document \
'{"Statement":[{"Action":"sts:AssumeRole","Effect":"Allow","Principal":{"Service":"ecs.amazonaws.com"}}],"Version": "2012-10-17"}'
echo creating role policy
aws iam put-role-policy --role-name $ROLE --policy-name blah --policy-document \
'{"Version":"2012-10-17","Statement":[{"Action":"elasticloadbalancing:Describe*","Effect":"Allow","Resource":"*"}]}'
echo creating load balancer $ELB
aws elb create-load-balancer --load-balancer-name $ELB --listeners "Protocol=HTTP,LoadBalancerPort=80,InstanceProtocol=HTTP,InstancePort=80" --availability-zones eu-west-1a
echo updating service...
aws ecs update-service --cluster $CLUSTER --service $SERVICE --desired-count 0
echo -n press any key to continue
read
echo deleting service
aws ecs delete-service --cluster $CLUSTER --service $SERVICE
echo deleting role policy
aws iam delete-role-policy --role-name $ROLE --policy-name blah
echo deleting role
aws iam delete-role --role-name $ROLE
echo deleting elb
aws elb delete-load-balancer --load-balancer-name $ELB
echo done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment