I have a small problem. I am starting a Task (docker container) via the JAVA SDK. This is working great.
But now I want to grab the public IP via the SDK and don't know how.
here is my existing code so far.
RunTaskRequest request = new RunTaskRequest()
.withCluster("JuiceShop")
.withTaskDefinition("startJuiceShop:1")
.withNetworkConfiguration(networkConfiguration)
.withLaunchType("FARGATE");
RunTaskResult response = client.runTask(request);
The response contains the Container but the network devices aren't attached yet. Is there a simple way to get the public IPV4?
You will need to make multiple AWS API calls to get Public IPv4 address. Here are the steps.
Example -
AmazonECS client = AmazonECSClientBuilder.standard().build();
DescribeTasksRequest request = new DescribeTasksRequest().withTasks("c5cba4eb-5dad-405e-96db-71ef8eefe6a8");
DescribeTasksResult response = client.describeTasks(request);
"attachments": [ { "id": "xxxxx-d02c-4a9d-ae79-xxxxxxx", "type": "ElasticNetworkInterface", "status": "ATTACHED", "details": [ { "name": "subnetId", "value": "subnet-xxxxx" }, { "name": "networkInterfaceId", "value": "eni-e5aa89a3" }, { "name": "macAddress", "value": "xxxxx" }, { "name": "privateIPv4Address", "value": "172.31.94.215" } ] } ],
Example -
AmazonEC2 client = AmazonEC2ClientBuilder.standard().build();
DescribeNetworkInterfacesRequest request = new DescribeNetworkInterfacesRequest().withNetworkInterfaceIds("eni-e5aa89a3");
DescribeNetworkInterfacesResult response = client.describeNetworkInterfaces(request);
{ "NetworkInterfaces": [ { "Association": { "IpOwnerId": "amazon", "PublicDnsName": "ec2-52-xx-xx-xx.compute-1.amazonaws.com", "PublicIp": "52.xx.xx.xx" } ] }
The task metadata endpoint will let you fetch network information about your container. If you're attaching an EIP you'll have to use the IPv4 from the container to find the EIP with the SDK.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.