Created
July 27, 2020 10:46
-
-
Save mims92/033c35b1c7d1f7d2386c4fcb2a26ec33 to your computer and use it in GitHub Desktop.
AWS - Bash - Get tasks instances
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 | |
#chmod +x /usr/bin/awsecs | |
#Usage: awsecs <service-name> <profile name> | |
#Output: list of ec2 instance id | |
SERVICE="$1" | |
shift | |
PROFILE="$1" | |
shift | |
CLUSTER="<<<<<<YOUR CLUSTER NAME>>>>>>" | |
tasks_arn=$(aws ecs list-tasks \ | |
--cluster "${CLUSTER}" \ | |
--service-name "${SERVICE}" \ | |
--profile "${PROFILE}" \ | |
| jq -r -c ".taskArns | join(\" \")"\ | |
) | |
container_instances_arn=$(aws ecs describe-tasks \ | |
--cluster "${CLUSTER}" \ | |
--tasks ${tasks_arn} \ | |
--profile "${PROFILE}" | jq -r -c ".tasks[].containerInstanceArn" \ | |
) | |
aws ecs describe-container-instances \ | |
--cluster "${CLUSTER}" \ | |
--container-instance ${container_instances_arn} \ | |
--profile "${PROFILE}" \ | |
| jq -r -c ".containerInstances[].ec2InstanceId" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment