How can I get Public IP of my FARGATE ECS task with metadata endpoint or java sdk?

风格不统一 提交于 2019-12-01 03:19:11

问题


I want to get public IP of my fargate ECS task after container started. I get IPv4Addresses when requested http://169.254.170.2/v2/metadata/ but I don't get public IP of task.

When I use runTask(request) method of RunTaskResult, again I don't get public IP from RunTaskResult.

Is there a way to get public IP of my fargate task something like http://169.254.169.254/latest/meta-data/public-hostname (for EC2)?


回答1:


I solved my problem with DescribeNetworkInterfacesRequest.I get private IP of my container with curl http://169.254.170.2/v2/metadata/ then run this code.

    AmazonEC2 ec2AsyncClient= AmazonEC2ClientBuilder.standard().withCredentials(new 
    AWSStaticCredentialsProvider(credentials)).build();

    DescribeNetworkInterfacesRequest request = new DescribeNetworkInterfacesRequest();
    request.withFilters(new Filter().withName("private-ip-address").withValues("my-container-private-Ip"));
    DescribeNetworkInterfacesResult result = ec2AsyncClient.describeNetworkInterfaces(request);
    String publicIP = result.getNetworkInterfaces().get(0).getAssociation().getPublicDnsName();


来源:https://stackoverflow.com/questions/50215187/how-can-i-get-public-ip-of-my-fargate-ecs-task-with-metadata-endpoint-or-java-sd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!