Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # ecsssh
- #
- # Given an ECS service, ssh to any EC2 instance running it.
- set -e
- set -o pipefail
- cluster=$(
- aws ecs list-clusters | jq -r '.clusterArns[]' \
- | fzf -0 --prompt 'cluster> ')
- service=$(
- aws ecs list-services --cluster ${cluster} | jq -r '.serviceArns[]' \
- | cut -d: -f6 | fzf -0 --prompt 'service> ' | tr '/' ':')
- # Any EC2 instances is good, so just pick the first one.
- c_instance=$(
- aws ecs list-container-instances --cluster ${cluster} \
- --filter "task:group =~ ${service}" \
- | jq -r '.containerInstanceArns[0]')
- instance_id=$(
- aws ecs describe-container-instances --cluster ${cluster} \
- --container-instances "${c_instance}" \
- | jq -r '.containerInstances[].ec2InstanceId')
- private_ip=$(
- aws ec2 describe-instances --output json \
- --filters "Name=instance-id,Values=${instance_id}" \
- --query 'Reservations[].Instances[]' \
- | jq -r '.[].PrivateIpAddress')
- if [ "$1" = "--show" ] ; then
- echo ${private_ip}
- else
- ssh ${private_ip}
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement