amazon-web-servicesaws-lambdaasp.net-core-mvcaws-alb

Why does an AWS ALB configured for a AspNetCore Lambda function give a 502 after when redirected?


I have project setup based on the AspNetCoreWebApp template from aws-lambda-dotnet.

The lambda entry point is setup the same as the template.

I can see an unsecured page fine, but when attempting to go to a secured page, I get a 502 Status Code response from the load balancer.

Based on aws troubleshooting:

The target response is malformed or contains HTTP headers that are not valid.

The lambda function redirects work fine fine with API Gateway in front of it.


Solution

  • Don't forget to read the Readme:

    Change the base class to Amazon.Lambda.AspNetCoreServer.ApplicationLoadBalancerFunction when using an Application Load Balancer.

    Although the Lambda function seems to work using the APIGatewayProxyFunction base class, the headers for Content-Type will come back as [null] during a redirect which the ALB does not appear to support. Change the base class of LambdaEntryPoint to ApplicationLoadBalancerFunction and the redirects will work correctly.