8

When accessing our static webpage hosted on an ALB served by a Lambda, we get a 502 bad gateway error. In the ALB logs, we can see that the error is that our Lambda response is larger than 1MB. We want to continue using an Application Load Balancer for our webpage, and need to find some way around this 1MB limit (can we deploy our code such that the Lambda returns multiple separate <1MB chunks of JS code?)

We looked online at other SO questions, and have found only a couple with people running into our issue, but no solutions provided. The AWS docs document this limitation, but again, no solutions are provided.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Zachary Steudel
  • 121
  • 1
  • 6
  • What is your motivation for the ALB-->Lambda architecture? Could you accomplish what you want by having the Lambda return a javascript wrapper around a signed URL to a resource hosted in S3 / Cloudfront? – Kevin Seaman Aug 08 '19 at 17:28
  • 1
    @KevinSeaman the simplest way to host the website would be to use the S3 / Cloudfront method, however this is an internal webpage we are using, and it seems either extremely needlessly complex to privatize the S3 bucket that would be hosting our resources, or even maybe not even possible. When you host a site using S3, it seems that you have to make the S3 bucket publicly accessible. – Zachary Steudel Aug 08 '19 at 19:45
  • It's actually quite trivial these days to restrict access to an s3 bucket (even one set as a web server) by IP address. It's just a bucket policy, you can enforce https using a bucket policy as well these days. S3 has come a long way in the last year or so. – K Mo Aug 08 '19 at 20:29
  • @ZacharySteudel, `seems that you have to make the S3 bucket publicly accessible` I have adopted this approach for internal web applications: https://www.proud2becloud.com/hosting-a-static-site-on-aws-is-cloudfront-always-the-right-choice/ – ePascoal Mar 10 '22 at 20:30

2 Answers2

4

We ended up deciding to switch off of the ALB and move to API Gateway. API Gateway can handle a 6MB return from a Lambda, so this should be fine for our purposes.

Zachary Steudel
  • 121
  • 1
  • 6
0

can we deploy our code such that the Lambda returns multiple separate <1MB chunks of JS code?

Kind of.

You can have your main page link to html or js referenced under a different path on the ALB and fed by a different Lambda.

For example the Lambda that responds on path '/' could return a response that references a script in the on path '/load' where a different Lambda returns a response specific to that path.

You could alternatively have a script in the main page that points to another html doc to be displayed on the main page. This could even be done recursively, e.g, '/' references '/one' which references '/two', etc.

Depending on the size of your original page, this strategy could get complex fast.

K Mo
  • 2,125
  • 8
  • 16
  • Dang, I see. We will look into this possibility, but I can definitely see the complexity rising. I will report back too and let you know if we end up taking this route. – Zachary Steudel Aug 08 '19 at 19:50