Is there a way to track which ECS task a request is forwarded to by a NLB?

0

According to the docs, NLB uses a flow hash algorithm:

For TCP traffic, the load balancer selects a target using a flow hash algorithm based on the protocol, source IP address, source port, destination IP address, destination port, and TCP sequence number. The TCP connections from a client have different source ports and sequence numbers, and can be routed to different targets. Each individual TCP connection is routed to a single target for the life of the connection.

https://docs.aws.amazon.com/elasticloadbalancing/latest/network/introduction.html

I'm trying to track what this looks like with our live traffic but I'm not seeing any metrics in CW that might tell me.

Is it possible to view metrics that could tell this story?

asked 3 months ago215 views
2 Answers
1
Accepted Answer

Hello.

I don't think you can see which task a request was assigned to using CloudWatch metrics.
https://docs.aws.amazon.com/AmazonECS/latest/userguide/monitoring-fargate-usage.html

Therefore, I think it is best to check the access logs and application logs of ECS Fargate tasks.
https://docs.aws.amazon.com/AmazonECS/latest/userguide/using_awslogs.html

profile picture
EXPERT
answered 3 months ago
1

Hi,

I believe that NLB request tracing adding a header X-Amzn-Trace-Id and forwarding is what you need: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-request-tracing.html

If you correlate this header with the CW logs at NLB, you can define which task gets which requets.

If your final goal is to track unhealthy targets, this blog post may help: https://aws.amazon.com/blogs/networking-and-content-delivery/identifying-unhealthy-targets-of-elastic-load-balancer/

Best,

Didier

profile pictureAWS
EXPERT
answered 3 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions