Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save output of AWS CLI in a variable?

I want to save output of an AWS CLI in a variable and use that variable in another AWS CLI, what I did is as follows:

taskarn= aws ecs list-tasks --cluster  mycluster --service-name "myService" --region "eu-west-1" --output text | grep "arn" | tr -d '"'

echo  $taskarn;  //empty
aws ecs stop-task --cluster mycluster --task $taskarn --region "eu-west-1"

when I echo $taskarn, it is empty.

Any help would be appreciated.

like image 664
Matrix Avatar asked Jan 28 '23 01:01

Matrix


1 Answers

I used the following command and it works fine:

taskarn=$(aws ecs list-tasks --cluster  mycluster --service-name "myservice" --region "eu-west-1" | grep "arn" | tr -d '"')
echo  $taskarn;

aws ecs stop-task --cluster mycluster --task $taskarn --region "eu-west-1"
like image 109
Matrix Avatar answered Feb 07 '23 14:02

Matrix