Burrow 是一个基于 AWS Lambda 构建的无服务器、全球分布式 HTTP 代理,专为 Go 语言设计。
它旨在与标准 Go *http.Client 完全兼容,这意味着它可以无缝地添加到许多现有应用程序中。Burrow 提供了 http.RoundTripper 接口的实现,通过一个或多个使用 Function URLs 暴露的 AWS Lambda 函数代理请求。
此外,还提供了一个轮询传输,可以轻松地在不同区域的多个 Lambda 函数之间自动轮换。
Burrow 为您提供了一个在不同区域旋转 IP 的网络,这在多种情况下都很有用,包括:
通过 Burrow 的单个请求性能可能较慢,特别是在路由到远距离区域时。然而,Burrow 专为 Go 中的高并发使用而设计,其中整体吞吐量比单个请求延迟更重要。
http.RoundTripper 实现的易用代理将 burrow 包添加到您的 Go 项目中:
go get github.com/myzie/burrow
在 http.Client 上启用:
proxy := "https://randomprefix.lambda-url.eu-west-2.on.aws/" client := &http.Client{Transport: burrow.NewTransport(proxy, "POST")} // 现在像平常一样使用 *http.Client
创建轮询传输:
proxies := []string{ "https://randomprefix1.lambda-url.us-east-1.on.aws/", "https://randomprefix2.lambda-url.us-east-2.on.aws/", "https://randomprefix3.lambda-url.us-west-1.on.aws/", } var transports []http.RoundTripper for _, u := range proxies { transports = append(transports, burrow.NewTransport(u, "POST")) } client := &http.Client{ Transport: burrow.NewRoundRobinTransport(transports), } // 客户端现在将为每个请求轮换使用提供的代理
或使用 burrow.NewRoundRobinClient 辅助函数:
client := burrow.NewRoundRobinClient([]string{ "https://randomprefix1.lambda-url.us-east-1.on.aws/", "https://randomprefix2.lambda-url.us-east-2.on.aws/", "https://randomprefix3.lambda-url.us-west-1.on.aws/", })
Burrow 包含 Terraform 配置,可以通过一个命令在您账户的 17 个默认启用的 AWS 区域中部署 Burrow:
make deploy BUCKET_NAME=my-terraform-state-bucket
命令完成后,将生成一个 function_urls.json 文件,其中包含每个区域中每个 Lambda 函数的 URL。然后,您可以在 Go 程序中读取此文件,并将这些值传递给 burrow.NewRoundRobinClient。
有关更多信息,请参阅 Makefile。您需要安装以下工具:
默认启用的 AWS 区域:
ap-northeast-1 - 东京
ap-northeast-2 - 首尔
ap-northeast-3 - 大阪
ap-south-1 - 孟买
ap-southeast-1 - 新加坡
ap-southeast-2 - 悉尼
ca-central-1 - 加拿大中部
eu-central-1 - 法兰克福
eu-north-1 - 斯德哥尔摩
eu-west-1 - 爱尔兰
eu-west-2 - 伦敦
eu-west-3 - 巴黎
sa-east-1 - 圣保罗
us-east-1 - 弗吉尼亚北部
us-east-2 - 俄亥俄州
us-west-1 - 加利福尼亚北部
us-west-2 - 俄勒冈州
多区域示例向 https://api.ipify.org?format=json 发送请求,以演示代理 IP 地址如何在不同区域之间变化。
$ go run ./cmd/example_multi_region {"ip":"13.36.171.187"} {"ip":"13.208.187.84"} {"ip":"18.142.184.58"} {"ip":"3.106.212.219"} {"ip":"13.60.11.169"} {"ip":"43.200.183.53"} {"ip":"3.127.170.76"} {"ip":"3.238.225.252"} {"ip":"54.185.130.119"} {"ip":"54.168.55.243"} {"ip":"13.201.18.225"} {"ip":"15.222.11.134"} {"ip":"54.247.221.168"} {"ip":"13.40.174.185"} {"ip":"15.228.175.92"} {"ip":"3.137.163.176"} {"ip":"54.177.165.5"} {"ip":"13.36.171.187"} # 回到第一个区域
Burrow 的作者 @myzie 可以提供合同工作和咨询服务。如果您需要有关 Go、AWS、Terraform、云安全或 SaaS 开发的帮助,欢迎通过 Github 或 LinkedIn 联系。请查看我的 个人资料 以获取我的 LinkedIn 信息。
欢迎贡献!请随时提交拉取请求。
Apache 许可证 2.0