问题描述
我想在容器启动后获取我的 fargate ECS 任务的公共 IP.我在请求时获得 IPv4Addresses http://169.254.170.2/v2/metadata/ 但我没有获取任务的公共IP.
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.
当我使用 RunTaskResult 的 runTask(request) 方法时,我再次没有从 RunTaskResult 获得公共 IP.
When I use runTask(request) method of RunTaskResult, again I don't get public IP from RunTaskResult.
有没有办法获得我的 fargate 任务的公共 IP,比如 http://169.254.169.254/latest/meta-data/public-hostname(对于EC2)?
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)?
推荐答案
我用 DescribeNetworkInterfacesRequest 解决了我的问题.我用 curl http://169.254.170.2/v2/metadata/ 然后运行此代码.
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();
这篇关于如何使用元数据端点或 java sdk 获取我的 FARGATE ECS 任务的公共 IP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!