这本质上与这个问题相同。然而,利用 VPC 端点的解决方案和利用 NAT 网关的解决方案对我来说不起作用,如下所述。
我的设置:
- VPC 的私有子网中有多个 lambda
- 公共子网中有一个 NAT 网关,允许 lambda 连接到互联网并访问外部 API(这工作得很好)
- 还有还有在私有子网中配置了正确的 URL
“com.amazonaws..sqs”
的 VPC 终端节点
- 安全组允许来自私有子网中的 lambda 的开放出口,但不允许不允许允许开放入口
当我的 Lamba 尝试发送到 SQS 时,我收到超时错误。但是,当我修改安全组以允许开放入口时,它就起作用了!
问题:
- 如何为 SQS VPC 端点/NAT 网关解决方案设置安全组,以便 VPC 中私有子网中的 lambda 发送到 SQS?
- 使用 VPC 终端节点是否需要开放入口?
- 如果是这样,为什么需要它?为了解决这个问题,我们尝试从 AWS 提取 IP 范围(此处)但没有 SQS 特定的 IP,因此我们被迫获取该区域中的所有 IP,并将其添加到一个安全组(或多个安全组,因为它们的数量很大)。
This is essentially the same question as this one. However, the solution utilizing the VPC Endpoint and the solution utilizing the NAT Gateway are not working for me as I describe below.
My setup:
- Multiple lambdas in private subnet of VPC
- There is a NAT Gateway in the public subnet that allows the lambdas to connect to the internet and reach an external API (this is working just fine)
- There is also a VPC Endpoint configured with the correct URL
"com.amazonaws.<REGION>.sqs"
in the private subnet
- Security group allows open egress from the lambdas in the private subnet, but does not allow open ingress
I get timeout errors in my Lambas when they try to send to SQS. However, when I modify the security group to allow open ingress, it works!
Questions:
- How are security groups meant to be setup for the SQS VPC Endpoint / NAT Gateway solutions for a lambda in a private subnet in a VPC to send to SQS?
- Is open ingress a requirement to use VPC Endpoint?
- If so, why is it required? To combat this, we tried pulling the ip-ranges (here) from AWS but there are no SQS-specific IPs so we are forced to get all of them in the region and add to a security group (or multiple, since there are a significant number of them).
发布评论
评论(1)
VPC 终端节点应具有一个安全组,该安全组允许从分配给 Lambda 函数的安全组进入。
VPC 终端节点的全部要点是允许将连接发送到终端节点,然后将连接转发到 VPC 外部存在的服务。如果您不允许任何到 VPC 终端节点的入口连接,则该终端节点将无法工作。
为什么要将 SQS IP 添加为 SQS VPC 终端节点的入口?我开始怀疑你是否混合了入口和出口。您说您的 Lambda 函数正在尝试发送到 SQS。发送是出口。 Lambda 函数需要一个允许出口到 SQS 的安全组。
VPC 终端节点需要接受来自 Lambda 函数的流量。来自 Lambda 函数的流量被视为 VPC 终端节点的入口流量。
对于通过 VPC 终端节点发送 SQS 消息的 Lambda 函数,您需要以下安全组:
Lambda 函数安全组:
入口:无
出口:连接到 VPC 终端节点安全组的端口 443,或者只是(所有) )
VPC 端点的安全组:
入口:来自 Lambda 函数安全组的端口 443
出口:(全部)
The VPC endpoint should have a security group that allows ingress from the security group that is assigned to the Lambda function.
The whole point of a VPC endpoint is to allow connections to be sent to the endpoint, that will then be forwarded to the service that exists outside the VPC. If you don't allow any ingress connections to the VPC endpoint then the endpoint will not work.
Why would you add SQS IPs as ingress to the SQS VPC endpoint? I'm starting to wonder if you are mixing ingress and egress. You said your Lambda function is trying to send to SQS. Sending is egress. The Lambda function needs a security group that allows egress to SQS.
The VPC Endpoint needs to accept traffic from the Lambda function. The traffic from the Lambda function is considered ingress traffic to the VPC endpoint.
For a Lambda function to send an SQS message via a VPC Endpoint you need the following security groups:
Lambda Function Security Group:
ingress: none
egress: port 443 to the VPC Endpoint's security group, or just (all)
VPC Endpoint's Security Group:
ingress: port 443 from the Lambda function's security group
egress: (all)