Skip to content

Commit 4e067b2

Browse files
committed
Fix a bug that failing fetching subnet information for EC2 tasks
1 parent 8e51a81 commit 4e067b2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

check-ecs-exec.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,13 +616,15 @@ fi
616616
# TODO: In the ideal world, the script should simply check if the task can reach to the internet or not :)
617617
requiredEndpoint="com.amazonaws.${AWS_REGION}.ssmmessages"
618618
taskNetworkingAttachment=$(echo "${describedTaskJson}" | jq -r ".tasks[0].attachments[0]")
619-
taskSubnetId=$(echo "${describedTaskJson}" | jq -r ".tasks[0].attachments[0].details[] | select(.name==\"subnetId\") | .value")
620-
subnetJson=$(${AWS_CLI_BIN} ec2 describe-subnets --subnet-ids "${taskSubnetId}")
621619
if [[ "x${taskNetworkingAttachment}" = "xnull" ]]; then
622620
## bridge/host networking (only for EC2)
623621
taskVpcId=$(echo "${describedContainerInstanceJson}" | jq -r ".containerInstances[0].attributes[] | select(.name==\"ecs.vpc-id\") | .value")
622+
taskSubnetId=$(echo "${describedContainerInstanceJson}" | jq -r ".containerInstances[0].attributes[] | select(.name==\"ecs.subnet-id\") | .value")
623+
subnetJson=$(${AWS_CLI_BIN} ec2 describe-subnets --subnet-ids "${taskSubnetId}")
624624
else
625625
## awsvpc networking (for both EC2 and Fargate)
626+
taskSubnetId=$(echo "${describedTaskJson}" | jq -r ".tasks[0].attachments[0].details[] | select(.name==\"subnetId\") | .value")
627+
subnetJson=$(${AWS_CLI_BIN} ec2 describe-subnets --subnet-ids "${taskSubnetId}")
626628
taskVpcId=$(echo "${subnetJson}" | jq -r ".Subnets[0].VpcId")
627629
fi
628630
## Obtain the ownerID of subnet's owner to check if the subnet is shared via AWS RAM (which check-ecs-exec.sh doesn't support today)

0 commit comments

Comments
 (0)