我已经设置了一个具有 3 个子网的 VPC,它可以从我的 Lambda 函数访问私有(private) RDS 实例。 RDS <-> Lambda 连接工作正常,但是现在我无法发布到 SNS。
我找到了关于 SNS 的 VPC 端点支持的公告(包括这篇博文 https://aws.amazon.com/blogs/security/securing-messages-published-to-amazon-sns-with-aws-privatelink/),并添加了具有以下属性的 VPC 端点接口(interface):
Service name: com.amazonaws.eu-west-1.sns
VPC: same as Lambda functions and other services
Subnets: all included in my VPC (have also tested toggling them individually)
Security Groups: all VPC security groups selected
所有服务都在 eu-west-1 地区。我知道发布到 SNS 的代码是正确的,因为它在非 VPC 环境中运行时有效。我发布到的 ARN 保持不变:
arn:aws:sns:eu-west-1:962446592636:whatever
.我知道可以设置一个 NAT 服务器来避免这个问题,但如果可能的话,我更喜欢使用 VPC 端点来降低成本。
最佳答案
这个对我有用!
我做了以下事情:
0.0.0.0/0
的所有 TCP(用于测试目的)所以,一切正常。我不必修改任何 Lambda 代码。
我的 Lambda 代码:
def lambda_handler(event, context):
import boto3
client = boto3.client('sns', region_name='ap-southeast-2')
response = client.publish(
TopicArn='arn:aws:sns:ap-southeast-2:123456789012:stack',
Message='From Lambda'
)
return
关于amazon-web-services - 如何使用 VPC Endpoint 从 VPC 内的 Lambda 发布到 SNS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50170420/