多个 AWS Lambda 向某些 HTTP(s) 资源发出请求是否会被检测为限制?

Will multiple AWS Lambdas making request to some HTTP(s) resource be detected as throttling?

假设我有多个 AWS Lambda 向某些 HTTP API 发出请求,是否有任何文档说明如何在节流方面 API 端看到这些请求。它们会被视为来自不同主机的请求,还是有时(或总是)来自同一主机的请求?

您应该假设同一个 Lambda 函数的 2 运行 甚至不会 运行 在同一台机器上。 AWS 可能会将同一实例重新用于 运行 您的函数,但这是为了节省在每次函数调用时下载代码所花费的时间。

您可以从此处的 AWS Lambda FAQ 页面找到here,如下:

Q: Will AWS Lambda reuse function instances?

To improve performance, AWS Lambda may choose to retain an instance of your function and reuse it to serve a subsequent request, rather than creating a new copy. To learn more about how Lambda reuses function instances, visit our documentation. Your code should not assume that this will always happen.

Q: Why must AWS Lambda functions be stateless?

Keeping functions stateless enables AWS Lambda to rapidly launch as many copies of the function as needed to scale to the rate of incoming events. While AWS Lambda’s programming model is stateless, your code can access stateful data by calling other web services, such as Amazon S3 or Amazon DynamoDB.

此外,要了解更多信息,请查看 this 有趣的博客 post(从 2014 年开始)

如果您将 Lambda 函数放在 VPC 之外,您的 API 将看到来自不同主机或有时来自同一主机的请求(这是不可预测的,因为 AWS 重用已经配置的热 Lambda 函数来处理请求相同的配置)

但是,如果您在为出口流量配置 NAT 网关时将 Lambda 函数放在私有子网中的 VPC 内,您的 API 将看到它们来自 NAT 网关 IP 地址。

根据您的要求,您可以使用其中大多数出于安全目的需要第二个选项的方法来将进入 API 的入口流量的 IP 列入白名单。