swagger-ui-bundle.js too large for AWS Lambda and ALB

Viewed 1274

Updated to .NET Core 3.1 and the latest version of Swashbuckle but found the swagger UI wasn't working correctly. The swagger-ui-bundle.js was failing to load with a 502. Tracked this down to a AWS ALB error saying the response was too big. ALB targeting Lambda limits responses to 1MB. Confirmed the swagger-ui-bundle.js is almost 1MB (technically 995KB).

Is there anyway to reduce the size of swagger-ui-bundle.js or some alternate way to reference it (through CDN maybe)?

I'm using the Swashbuckle.AspNetCore 5.5.1 Nuget package with .NET Core 3.1.

1 Answers

This should fix the issue:

app.UseSwaggerUI(c => {
  c.InjectJavascript("https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.1.3/swagger-ui-bundle.js", "text/javascript");
  c.SwaggerEndpoint($"/swagger/{_swaggerVersion}/swagger.json", _appSettings.ApiName);
});
Related