AWS Lambda with ALB – Seemingly random 502 errors

Hit an issue this week as I was upgrading a service from .NET Core 2.1 to .NET Core 3.1.  After the upgrade everything worked locally so we deployed to our AWS environment.  This service is executed via Lambda and routed requests through ALB.

Everything also seemed to work in AWS except for our Swagger UI page.  Through further troubleshooting found the swagger-ui-bundles.js file that the Swagger UI page requests was coming back with a 502 – Bad Gateway response code.  Other js/css files on the page loaded without any problem.

Initially I suspected a bug in the latest version of the Swashbuckle Nuget package for .NET 3.1 but that should occur locally as well.  Since this was only occurring in AWS I started suspecting the ALB.  So I enabled the Access logs so I could get more info about this particular request:

image

After hitting the page and waiting a few minutes the S3 buckets started filling with logs.  Sure enough found the error message for these requests “LambdaResponseTooLarge”.

Then found the ALB and Lambda documentation:

The maximum size of the request body that you can send to a Lambda function is 1 MB. For related size limits, see HTTP header limits.

https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html

Actually surprised I haven’t hit this limit before but that was my problem.  Further found this had already been reported to the Swagger UI project and they are working on a fix to get the file size down.

Hope that helps someone else with the same error and they find the fix a little be quicker.

Cheers!

Leave a Reply