Last active
December 7, 2023 16:50
-
-
Save hakanilter/e5961a3c25689ceef3f47ddd4ba91208 to your computer and use it in GitHub Desktop.
AWS ECS run task and wait for the result
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Requies JSON as the output format and "jq" commandline tool | |
# If task runs successfuly, exits 0 | |
run_result=$(aws ecs run-task \ | |
--cluster ${CLUSTER} \ | |
--task-definition ${TASK_DEFINITION} \ | |
--launch-type EC2 \ | |
--overrides "${OVERRIDES}") | |
echo ${run_result} | |
container_arn=$(echo $run_result | jq -r '.tasks[0].taskArn') | |
aws ecs wait tasks-stopped \ | |
--cluster ${CLUSTER} \ | |
--tasks "${container_arn}" |
Thanks for the update @mpozniak !
Here is an approach without needing jq
container_arn=$(aws ecs run-task \
--cluster ${CLUSTER} \
--task-definition ${TASK_DEFINITION} \
--launch-type EC2 \
--query tasks[0].taskArn \
--output text \
--overrides "${OVERRIDES}")
aws ecs wait tasks-stopped \
--cluster ${CLUSTER} \
--tasks "${container_arn}"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use 'jq -r' to avoid using sed to remove ' " ' (escaping characters):
jq --help:
"-r output raw strings, not JSON texts;"