How to fetch the external link of aws ecs task running which has the public ip of container instance and port of the task running?
I am managing task/service execution from cli and would like to fetch the external link which is shown in the aws UI from aws cli. I tried describe-tasks command of aws cli but it doesn't return the public IP address of the instance the task is running on.
Is there a way to fetch the same from aws cli?
Thanks in advance!
This is quite the pain in the neck, but it will do what you want:
aws ecs list-tasks --cluster mycluster --service-name my-service-name
aws ecs describe-tasks --cluster mycluster --tasks arn:aws:ecs:us-east-1:999999999999:task/ad0ba3e9-ac3b-4a4c-a1af-de3e06f46dfa
aws ecs describe-container-instances --cluster mycluster --container-instances arn:aws:ecs:us-east-1:999999999999:container-instance/707e5193-51e3-454b-ba09-9745c5d7f527
aws ec2 describe-instances --instance-ids i-c91aee40d92c23b3c
^^^^ NOT ECS
The output of this command should include the private IP of the EC2 instance. This IP + previously computed port should correspond to the external link from the web UI.
NOTE: Data has been anonymized, but should still LOOK like what you can expect to see. Also I omitted AWS region and profile params, which I have set to defaults using environment variables.
This should show your Ingress IP address which is a public URL and is typically then mapped to your domain as a Type A record using AWS route53 console so your users can reach same just using your URL domain.com/lalala
aws ecs describe-services --service my-http-service
to discover this command and others generally the aws
command line tool is actually very friendly ... just issue
aws help
then view that top level list of available subcommands then drill down by issuing
aws ecs help
and repeat above burrowing deeper into the available commands until you reach what could work ... as in
ecs ecs describe-services help
You can get to the answer you want by running:
aws ecs describe-tasks --cluster foo --tasks 8591006e-6f05-4886-bc4a-58d9063d3852
This will contain the networkBindings section like this:
"networkBindings": [
{
"protocol": "tcp",
"bindIP": "0.0.0.0",
"containerPort": 7000,
"hostPort": 32769
},
{
"protocol": "tcp",
"bindIP": "0.0.0.0",
"containerPort": 7001,
"hostPort": 32768
}
]
Then you're golden!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With