Search code examples
amazon-web-servicesamazon-ecsamazon-elb

AWS NLB to ECS Cluster failing health check


I've configured a Network Load Balancer to route TCP traffic to an ECS cluster over port 80

The ECS cluster is running an ASP.NET Core 2.2 API task in Fargate configuration. The base route for the API is http://ip_address:80/api/v1/

At first, everything works as expected, I can hit the load balancer's DNS and route requests to the appropriate .NET API route

However, eventually the health check on the NLB fails, the containers are drained and new container replace them.

With an Application Load Balancer I would just configure the health check to hit a /healthcheck route on the API and everything would be fine.

However, a Network Balancer can't be configured this way.

My question is: What is the strategy for carrying out health checks on an ECS container?


Solution

  • OK so the answer was fairly simple...

    You just set up a resource on the / path so that the NLB get's a response

    My concrete solution for asp.net core:

    ASP.NET Core 2.2 has a built in package for this. It was just a matter of adding the following in the Startup.cs class

    Add the service to service collection

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddHealthChecks();
    }
    

    Configure the health check

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        // Network Load Balancer hits this path for the health check
        app.UseHealthChecks("/", 80);
        ...
    }