1

I have a Java application running on AWS Fargate. EC2MetadataUtils.getAvailabilityZone() returns null from within an AWS Fargate

Is there an alternative way to determine which AZ the fargate container is running in? I also have the subnet id for the container

dogfish
  • 2,646
  • 4
  • 21
  • 37
  • Shouldn‘t this be possible via the task metadata endpoint? See https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint.html – Dirk Lachowski Aug 27 '18 at 22:34
  • I don't see the AZ there using the task metadata endpoint. Are you able to get this info there ? – dogfish Aug 27 '18 at 22:45
  • EC2MetzdataUtils is a wrapper for the metadata endpoint, so if its not in one it won't be in the other https://github.com/aws/aws-sdk-java/blob/master/aws-java-sdk-core/src/main/java/com/amazonaws/util/EC2MetadataUtils.java#L71 – Cheruvian Aug 28 '18 at 00:58

1 Answers1

1

I'm not familiar with the Java SDK, but it's likely just a wrapper around the awscli itself. So here is a slightly more abstract, SDK-independent way to do it. You ought to be able to easily adapt to whatever SDK.

  1. Use the metadata endpoint to determine the private ip of the ENI attached to the container in question.

  2. describe-network-interfaces and filter by private ip, using the ip you retrieved from the metadata service. The results of this query should include the ENI attached to your task, and in that returned object it will list the availability zone where the ENI is running.

bluescores
  • 4,437
  • 1
  • 20
  • 34