Created
July 3, 2020 02:28
-
-
Save adiii717/fca85afe24f74a7259cf87ec058c00db to your computer and use it in GitHub Desktop.
Find instance or instance ID of AWS ECS running TASK or Services
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CLUSTER_NAME=default | |
CONTAINER_INSTANCE="$(aws ecs list-container-instances --cluster $CLUSTER_NAME --query 'containerInstanceArns[]' --output text)" | |
for container in $CONTAINER_INSTANCE; do | |
TASK=$(aws ecs list-tasks --cluster $CLUSTER_NAME --container-instance $container --query 'taskArns[]' --output text) | |
EC2_INSTANCE_ID=$(aws ecs describe-container-instances --cluster prod-bgworker --container-instances $container --region us-west-2 --query 'containerInstances[*].ec2InstanceId' --output text) | |
echo "**************************************" | |
echo "ECS TASK having ARN is $TASK" | |
echo "Running in EC2 instance having ID $EC2_INSTANCE_ID" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment