最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - "502 bad gateway" - 1MB limit static page served from AWS Lambda to Application Load Balancer - S

programmeradmin0浏览0评论

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.

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.

Share Improve this question edited Aug 9, 2019 at 0:24 John Rotenstein 271k28 gold badges447 silver badges531 bronze badges asked Aug 8, 2019 at 16:23 Zachary SteudelZachary Steudel 1311 silver badge6 bronze badges 4
  • What is your motivation for the ALB-->Lambda architecture? Could you acplish what you want by having the Lambda return a javascript wrapper around a signed URL to a resource hosted in S3 / Cloudfront? – Kevin Seaman Commented Aug 8, 2019 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 plex 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 Commented Aug 8, 2019 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 e a long way in the last year or so. – K Mo Commented Aug 8, 2019 at 20:29
  • @ZacharySteudel, seems that you have to make the S3 bucket publicly accessible I have adopted this approach for internal web applications: proud2becloud./… – ePascoal Commented Mar 10, 2022 at 20:30
Add a ment  | 

2 Answers 2

Reset to default 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.

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 plex fast.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论