为什么 VPC 中的 aws lambda 无法向 SNS 发送消息?

Why aws lambda within VPC can not send message to SNS?

我的 lambda 函数可以使用 "no VPC" 的发布方法向 SNS 发送消息,但是当我将它放在一个 VPC 中时它会超时,该 VPC 可以使用路由和互联网网关访问 public 互联网。

已编辑

我的 lambda 位于 public 子网中,其中 0.0.0.0/0 已路由到互联网网关,因此无法将其再次路由到 NAT。是否可以将 EIP 分配给 lambda 函数

您必须添加一个 NAT Gateway to your VPC in order for Lambda functions (and other things in your VPC that don't have a public IP) to access anything outside the VPC. You should read the Things to Know section of this AWS announcement

启用VPC 后无法访问外部Internet。因此,当您使用 boto3 等库发送发布到 SNS 主题的请求时,您的请求将会超时。

NAT 是一种选择,但一种更具成本效益的方法是从您的 VPN 设置一个到 SNS 的接口端点。您可以转到 AWS VPN 控制台并创建一个端点和 select SNS 作为服务。

以下是有关如何设置接口端点的更多详细信息:https://docs.aws.amazon.com/vpc/latest/userguide/vpce-interface.html#create-interface-endpoint