【发布时间】:2020-01-18 07:57:00
【问题描述】:
我正在使用无服务器框架在 AWS 上创建 Lambda。
我添加了这个简单的代码来测试我的 lambda 中的互联网连接
try:
# see if we can resolve the host name -- tells us if there is
# a DNS listening
host = socket.gethostbyname('www.google.com')
# connect to the host -- tells us if the host is actually
# reachable
s = socket.create_connection((host, 80), 2)
s.close()
logging.info('Internet connectivity is present')
except Exception as e:
logging.info('Internet connectivity is not present: {}'.format(e))
此代码始终无法连接到 Internet,提示为 timed out。我正在我自己的 VPC 中启动我的 lambda(具体而言,我正在重新使用 RDS VPC)
我创建了自己的 VPC,它有几个子网,每个子网都连接到 Internet 网关
这就是我的安全组配置的样子
如给定的here,如果子网有 igw 路由,那么它应该可以访问 Internet。我已经通过启动 EC2 实例并尝试从那里 ping 来验证这一点,并且我成功地这样做了。
我在这里缺少什么?如何通过我的 Lambda 代码启用 Internet 访问?
【问题讨论】:
标签: python amazon-web-services aws-lambda serverless-framework