Skip to content

Commit c8cfd4a

Browse files
committed
Add task existence check before AWS CLI version check.
1 parent 7eb24d8 commit c8cfd4a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

check-ecs-exec.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,19 @@ callerIdentityJson=$(${AWS_CLI_BIN} sts get-caller-identity)
123123
ACCOUNT_ID=$(echo "${callerIdentityJson}" | jq -r ".Account")
124124
MY_IAM_ARN=$(echo "${callerIdentityJson}" | jq -r ".Arn")
125125

126-
# Check whether the AWS CLI v1.19.28/v2.1.30 or later exists
126+
# Check task existence
127127
describedTaskJson=$(${AWS_CLI_BIN} ecs describe-tasks \
128128
--cluster "${CLUSTER_NAME}" \
129129
--tasks "${TASK_ID}" \
130130
--output json)
131+
existTask=$(echo "${describedTaskJson}" | jq -r ".tasks[0].taskDefinitionArn")
132+
if [[ "x${existTask}" = "xnull" ]]; then
133+
printf "${COLOR_RED}Pre-flight check failed: The specified ECS task does not exist.\n\
134+
Make sure the parameters you have specified for cluster \"${CLUSTER_NAME}\" and task \"${TASK_ID}\" are both valid.\n"
135+
exit 1
136+
fi
137+
138+
# Check whether the AWS CLI v1.19.28/v2.1.30 or later exists
131139
executeCommandEnabled=$(echo "${describedTaskJson}" | jq -r ".tasks[0].enableExecuteCommand")
132140
if [[ "x${executeCommandEnabled}" = "xnull" ]]; then
133141
printf "${COLOR_RED}Pre-flight check failed: ECS Exec requires the AWS CLI v1.19.28/v2.1.30 or later.\n\

0 commit comments

Comments
 (0)