#!/bin/sh
AWS_PROFILE=default
ECS_CLUSTER=cluster_name
CONTAINER_NAME=migrate
# Run task and get its arn
# NOTE: many of the necessary cli inputs have been omitted here
TASK_ARN=$(aws ecs run-task \
--cluster $ECS_CLUSTER \
--query 'tasks[].taskArn' \
--output text | rev | cut -d'/' -f1 | rev)
# Wait for ecs task to stop
aws ecs wait tasks-stopped \
--cluster $ECS_CLUSTER \
--tasks $TASK_ARN
# Get exit code
TASK_EXIT_CODE=$(aws ecs describe-tasks \
--cluster $ECS_CLUSTER \
--tasks $TASK_ARN \
--query "tasks[0].containers[?name=='$CONTAINER_NAME'].exitCode" \
--output text)
echo "The $TASK_ARN ran in ECS cluster $ECS_CLUSTER and its $CONTAINER_NAME returned exit code $TASK_EXIT_CODE"
# exit with the same code
exit $TASK_EXIT_CODE
2条答案
按热度按时间cpjpxq1n1#
这是我获取任务的特定容器名称的退出代码的方法
在脚本中
如果有多个容器,最好在退出之前
sum
退出代码,或者单独检查每个容器。xuo3flqw2#
每个容器的退出代码可以通过
DescribeTasks
API作为exitCode
获得。