Home > OS >  How to get Remote/Client IP address or domain in service deployed in AWS APP Mesh
How to get Remote/Client IP address or domain in service deployed in AWS APP Mesh

Time:10-06

We have multiple microservices deployed in AWS App Mesh. All the services are developed in Spring Boot and deployed in AWS fargate.

I need to find the service IP/domain from which the API is called. In Java, this can be done by calling getRemoteHost() or getRemoteAddr() on icoming request. But currently, it's returning, 127.0.0.1 for both the calls.

Could it be because of the envoy proxy deployed along with the service? How do I get caller IP in services deployed in app mesh?

CodePudding user response:

Based on this image, App Mesh seems to be fronted by a load balancer with the traffic routed to a Virtual Gateway and finally to the various clients.

enter image description here

This should mean that simply getting the value of the X-Forwarded-For header from the incoming HTTP request should be enough to retrieve a client's IP address. You can read more on that here.

CodePudding user response:

The X-Forwarded-For request header is automatically added and helps you identify the IP address of a client when you use an HTTP or HTTPS load balancer. From AWS documentation, the X-Forwarded-For request header may contain multiple IP addresses that are comma separated. The left-most address is the client IP where the request was first made. You need to check for it in the request that your Spring Boot app gets.

  • Related