Skip to content

Commit 4719a12

Browse files
committed
Minor updates on script comments
1 parent 5380906 commit 4719a12

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

check-ecs-exec.sh

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@ COLOR_RED='\033[0;31m'
4949
COLOR_YELLOW='\033[1;33m'
5050
COLOR_GREEN='\033[0;32m'
5151

52-
# Required parameters
52+
# Validation for required parameters
5353
CLUSTER_NAME=${1:-None} # A cluster name or a full ARN of the cluster
5454
TASK_ID=${2:-None} # A task ID or a full ARN of the task
55-
# Validation
5655
if [[ "x${CLUSTER_NAME}" = "xNone" || "x${TASK_ID}" = "xNone" ]]; then
5756
printf "${COLOR_RED}Usage:\n" >&2
5857
printf " ./check-ecs-exec.sh YOUR_ECS_CLUSTER_NAME YOUR_ECS_TASK_ID\n" >&2
@@ -85,7 +84,7 @@ showEvalResult() {
8584
printf "${COLOR_GREEN}${evalResult}\n"
8685
else
8786
printf "${COLOR_RED}${evalResult}\n"
88-
fi
87+
fi
8988
}
9089

9190
## 1. CHECK PREREQUISITES FOR check-ecs-exec.sh ##########################################
@@ -124,7 +123,7 @@ callerIdentityJson=$(${AWS_CLI_BIN} sts get-caller-identity)
124123
ACCOUNT_ID=$(echo "${callerIdentityJson}" | jq -r ".Account")
125124
MY_IAM_ARN=$(echo "${callerIdentityJson}" | jq -r ".Arn")
126125

127-
# Check if the AWS CLI v1.19.28/v2.1.30 or later exists
126+
# Check whether the AWS CLI v1.19.28/v2.1.30 or later exists
128127
describedTaskJson=$(${AWS_CLI_BIN} ecs describe-tasks \
129128
--cluster "${CLUSTER_NAME}" \
130129
--tasks "${TASK_ID}" \
@@ -140,7 +139,7 @@ fi
140139
awsCliVersion=$(${AWS_CLI_BIN} --version 2>&1)
141140
printf "${COLOR_DEFAULT} AWS CLI Version | ${COLOR_GREEN}OK ${COLOR_DEFAULT}(${awsCliVersion})\n"
142141

143-
# Check if the Session Manager plugin exists
142+
# Check whether the Session Manager plugin exists
144143
printf "${COLOR_DEFAULT} Session Manager Plugin | "
145144
command -v session-manager-plugin >/dev/null 2>&1 && status="$?" || status="$?"
146145
if [[ "${status}" = 0 ]]; then
@@ -161,7 +160,7 @@ printf "${COLOR_DEFAULT}Task : ${TASK_ID}\n"
161160
printSectionHeaderLine
162161
##########################################################################################
163162

164-
# 1. Check the cluster configurations
163+
# 1. Checks on the cluster configurations
165164
describedClusterJson=$(${AWS_CLI_BIN} ecs describe-clusters \
166165
--clusters "${CLUSTER_NAME}" \
167166
--include CONFIGURATIONS \
@@ -230,7 +229,7 @@ else
230229
fi
231230
printf "\n"
232231

233-
# 2. Check if "I" can call ecs:ExecuteCommand
232+
# 2. Check whether "I" can call ecs:ExecuteCommand
234233
printf "${COLOR_DEFAULT} Can I ExecuteCommand? | ${MY_IAM_ARN}\n"
235234
ecsExecuteCommand="ecs:ExecuteCommand"
236235
ecsExecEvalResult=$(${AWS_CLI_BIN} iam simulate-principal-policy \
@@ -288,7 +287,7 @@ else
288287
printf "${COLOR_YELLOW}UNKNOWN\n"
289288
fi
290289

291-
# 4. Check if the `execute-command` option is enabled for the task
290+
# 4. Check whether the `execute-command` option is enabled for the task
292291
printf "${COLOR_DEFAULT} Exec Enabled for Task | "
293292
if [[ "x${executeCommandEnabled}" = "xtrue" ]]; then
294293
printf "${COLOR_GREEN}OK"
@@ -330,7 +329,7 @@ taskRoleArn=$(echo "${taskDefJson}" | jq -r ".taskDefinition.taskRoleArn")
330329
hasRole=true
331330
isEC2Role=false
332331
if [[ "x${taskRoleArn}" = "xnull" ]]; then
333-
## Check if the task has an underlying EC2 instance and it has a IAM role through its instance profile
332+
## When the task runs on EC2 without a task role then we should check the instance profile
334333
if [[ "x${launchType}" = "xEC2" ]]; then
335334
ec2InstanceId=$(echo "${describedContainerInstanceJson}" | jq -r ".containerInstances[0].ec2InstanceId")
336335
instanceProfileArn=$(${AWS_CLI_BIN} ec2 describe-instances --instance-ids "${ec2InstanceId}" | jq -r ".Reservations[0].Instances[0].IamInstanceProfile.Arn")
@@ -455,7 +454,7 @@ else
455454
fi
456455

457456
# 7. Check existing VPC Endpoints (PrivateLinks) in the task VPC.
458-
# If there is any VPC Endpoints configured for the task VPC, this means it would need an additional SSM PrivateLink to be configured.
457+
# If there is any VPC Endpoints configured for the task VPC, we assume you would need an additional SSM PrivateLink to be configured.
459458
# TODO: In the ideal world, the script should simply check if the task can reach to the internet or not :)
460459
taskNetworkingAttachment=$(echo "${describedTaskJson}" | jq -r ".tasks[0].attachments[0]")
461460
taskVpcId=""
@@ -475,7 +474,7 @@ printf "${COLOR_DEFAULT} VPC Endpoints | "
475474
if [[ "x${vpcEndpoints}" = "x" ]]; then
476475
printf "${COLOR_GREEN}SKIPPED ${COLOR_DEFAULT}(${taskVpcId} - No additional VPC endpoints required)\n"
477476
else
478-
# Check if a ssmmessages VPC endpoint already exists, if there is any existing VPC endpoints found
477+
# Check whether an ssmmessages VPC endpoint exists
479478
vpcEndpoints=$(echo "${vpcEndpointsJson}" | tr -d '\n' | jq -r ".VpcEndpoints[].ServiceName")
480479
printf "\n"
481480
ssmsessionVpcEndpointExists=false

0 commit comments

Comments
 (0)