Skip to content

Commit

Permalink
Add ecs-utils script
Browse files Browse the repository at this point in the history
  • Loading branch information
quangnhnhut123 committed Jan 8, 2025
1 parent f6a2e32 commit 36a8419
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ RUN yum update -y && \
COPY ./check-connections.sh /usr/local/bin/check-connections.sh
COPY ./check-envs.sh /usr/local/bin/check-envs.sh
COPY ./ssm-compare.sh /usr/local/bin/ssm-compare.sh
COPY ./ecs-utils.sh /usr/local/bin/ecs-utils.sh

RUN chmod +x /usr/local/bin/check-connections.sh
RUN chmod +x /usr/local/bin/check-envs.sh
RUN chmod +x /usr/local/bin/ssm-compare.sh
RUN chmod +x /usr/local/bin/ecs-utils.sh
27 changes: 27 additions & 0 deletions ecs-utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# Check if CLUSTER_NAME and NUMBER_OF_TASK are provided as arguments
if [ -z "$1" ]; then
echo "Usage: $0 <CLUSTER_NAME> <NUMBER_OF_TASK>"
exit 1
fi

# Configurable parameters
CLUSTER_NAME="$1"
NUMBER_OF_TASK="$2"

echo "Retrieving services in cluster $CLUSTER_NAME..."
SERVICES=$(aws ecs list-services --cluster "$CLUSTER_NAME" --query "serviceArns[]" --output text)

for SERVICE_ARN in $SERVICES;
do
SERVICE_NAME=$(echo $SERVICE_ARN | awk -F/ '{print $NF}')
echo "Scaling ECS service $SERVICE_NAME in cluster $CLUSTER_NAME to $NUMBER_OF_TASK..."
aws ecs update-service --cluster "$CLUSTER_NAME" --service "$SERVICE_NAME" --desired-count $NUMBER_OF_TASK > /dev/null 2>&1

if [ $? -eq 0 ]; then
echo "Successfully scaled ECS service $SERVICE_NAME to $NUMBER_OF_TASK tasks."
else
echo "Failed to scale ECS service $SERVICE_NAME."
fi
done

0 comments on commit 36a8419

Please sign in to comment.