Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stopping task on AWS ECS via CLI (program output as argument input bash)

I'm trying to kill a task in ECS via the CLI.

I can fetch the task name by executing:

aws ecs list-tasks --cluster "my-cluster" --service-name "my-service" | jq .taskArns[0]

which outputs:

"arn:aws:ecs:REGION:ACCOUNT-ID:task/TASK-GUID"

the full ARN of the task as a string (I have a global defaulting output to JSON).

I can kill the task by executing:

aws ecs stop-task --cluster "my-cluster" --task "task-arn"

However when I try and combine it:

aws ecs stop-task --cluster "my-cluster" --task $(aws ecs list-tasks --cluster "my-cluster" --service-name "my-service" | jq .taskArns[0])

I get:

An error occurred (InvalidParameterException) when calling the StopTask operation: taskId longer than 36.

I know this is probably bash program output/argument input interpolation but I've looked that up and cannot get to the bottom of it.

like image 848
Simon Avatar asked Jun 19 '17 13:06

Simon


People also ask

How do you stop an AWS ECS task after it has completed its task?

exit(); to terminate the program. This is how the task was Stopped in the cluster.

How do you stop ECS in AWS?

In the ECS Cluster view, click Tasks on the left. Make sure Desired Task Status is set to Running . Choose the individual tasks to stop and then click Stop or click Stop All to select and stop all running tasks.


1 Answers

AWS cli essentially has jq built in so a better (simpler) way to query your task arn would be with:

aws ecs list-tasks --cluster "my-cluster" --service "my-service" --output text --query taskArns[0]
like image 90
nathanpeck Avatar answered Oct 16 '22 22:10

nathanpeck