# クラスタ名からEC2インスタンスIDを取得
CLS=sample-cluster
instanceID=$(aws ecs describe-container-instances --cluster $CLS --container-instances "$(aws ecs list-container-instances --cluster $CLS --query containerInstanceArns)" --query "containerInstances[].ec2InstanceId" --output text)
# インスタンスIDからパブリックIP取得
publicIp=$(aws ec2 describe-instances --instance-ids $instanceID --query "Reservations[].Instances[].NetworkInterfaces[].PrivateIpAddresses[].Association.PublicIp" --output text)
# ECSのコンテナに対してdocker exec経由でコマンドを実行
ssh ec2-user@$publicIp docker exec \$\(docker ps --filter ancestor=999999999999.dkr.ecr.ap-northeast-1.amazonaws.com/sample:latest --format "{{.ID}}"\) ls
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme