Skip to content

Commit 974c2a0

Browse files
authored
Merge pull request #8 from Anorlondo448/add_taskdef_existence_check
Add task existence check before AWS CLI version check
2 parents 1cdcfeb + c8cfd4a commit 974c2a0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

check-ecs-exec.sh

+9-1
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,19 @@ callerIdentityJson=$(${AWS_CLI_BIN} sts get-caller-identity)
124124
ACCOUNT_ID=$(echo "${callerIdentityJson}" | jq -r ".Account")
125125
MY_IAM_ARN=$(echo "${callerIdentityJson}" | jq -r ".Arn")
126126

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