大网数据广告活动
服务器运维问答

Store request body of route without hitting web server in AWS

· 52CE 我爱测

Let's say I have a website: mysite.com , running on AWS, served from some EC2 instances behind an Application Load Balancer. The load balancer terminates SSL through an ACM certificate. I need to route incoming requests to a URL …

问题原文

原帖链接 · Marc Fowler · CC BY-SA 3.0

Let's say I have a website: mysite.com, running on AWS, served from some EC2 instances behind an Application Load Balancer. The load balancer terminates SSL through an ACM certificate.

I need to route incoming requests to a URL (example: mysite.com/{user_id}/something/here/) away from the load balancer and instead send them to a Lambda function (more specifically, I want to just capture the request body and write it somewhere and then return an HTTP 200; it doesn't have to be done via a Lambda function).

The ALB lets you route to different target groups, but they can only contain EC2 instances it seems. The docs state "You register targets, such as EC2 instances, with a target group" - what else can be added if not only EC2 instances?

I don't want to have to run my own instance of haproxy etc, nor route them via nginx once the requests go through the ALB and hit the web servers, because the point of this exercise is to reduce things I have to manage, not increase them!

Is there a way around this?

已采纳解答

原帖链接 · Michael - sqlbot · CC BY-SA 3.0

You register targets, such as EC2 instances, with a target group.

http://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-target-groups.html

You've made an astute observation. That's an interesting choice of words... but, for the moment at least, EC2 instances are the only kind of target.

An EC2 instance either invoking your Lambda functions or proxying them to API Gateway (with Nginx or HAProxy) is a reasonable way to go. If you're not familiar with using an instance just as a proxy, you'll likely be surprised at how much traffic you can push through even tiny instances when proxying is all the work they are doing. (I have t2.micro and t2.nano instances with HAProxy that proxy well over 1 million requests per day without ever exceeding 5% CPU).

But, if you want to reduce the things you have to manage, keep everything in one domain, and pluck off certain paths, you can use CloudFront in front of the ALB, to route certain path patterns elsewhere -- such as to API gateway. (Bonus: you can integrate static assets from S3 into your site with this solution, too. You can even route requests to servers and services external to AWS, by path pattern matching.) CloudFront is marketed as a CDN, but it also happens to be an infinitely scalable reverse proxy.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-06-23)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。