Skip to content

Instantly share code, notes, and snippets.

@travisjeffery
Created December 16, 2015 23:53
Show Gist options
  • Select an option

  • Save travisjeffery/5142c960765a95e26fd8 to your computer and use it in GitHub Desktop.

Select an option

Save travisjeffery/5142c960765a95e26fd8 to your computer and use it in GitHub Desktop.
host=$1
echo "finding host for container: $1"
function ec2-ip () {
aws ec2 describe-instances --filter Name=instance-id,Values=$1 | jq '.Reservations[0].Instances[0].PrivateIpAddress' | tr -d '"'
}
instances=$(aws ecs list-container-instances --cluster api --max-items 100 | jq '.containerInstanceArns | .[]' | tr -d '"')
ids=$(echo $instances | xargs aws ecs describe-container-instances --cluster api --container-instances | jq '.containerInstances | .[] | .ec2InstanceId' | tr -d '""')
for id in $ids; do
ip=$(ec2-ip $id)
if $(ssh -o LogLevel=quiet -o UserKnownHostsFile=/dev/null -o "StrictHostKeyChecking no" -i ~/.ssh/launchpad.pem ec2-user@$ip "docker ps | grep -q $host"); then
echo "ip is $ip"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment