【发布时间】:2020-03-02 04:06:45
【问题描述】:
我在 VPC 中有一个 lambda,因为它需要访问数据库。现在,这个 lambda 还必须能够使用 Firehose Kinesis 视频流 (https://aws.amazon.com/kinesis/video-streams/)。我的 lambda 是用 Python 构建的,这是我创建 kinesis 视频客户端的代码:
client = boto3.client('kinesisvideo')
def create_stream(stream_name):
response = client.create_stream(
DeviceName='BE',
StreamName=stream_name,
MediaType='video/h264',
DataRetentionInHours=1,
Tags={
'string': 'Livestream'
}
)
stream_ARN = response['StreamARN']
print('Printing ARN: ', stream_ARN)
return stream_ARN
现在当我调用 create_stream('TEST') 时,我的 lambda 会在 90 秒后超时:
[DEBUG] 2019-11-05T15:02:47.66Z 2e094ebe-8a92-4a10-ab6c-433cf223cb5b retry needed, retryable exception caught: Connect timeout on endpoint URL: "https://kinesisvideo.eu-west-1.amazonaws.com/createStream"
Traceback (most recent call last):
File "/var/runtime/urllib3/connection.py", line 160, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw)
File "/var/runtime/urllib3/util/connection.py", line 80, in create_connection
raise err
File "/var/runtime/urllib3/util/connection.py", line 70, in create_connection
sock.connect(sa)
socket.timeout: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/var/runtime/botocore/httpsession.py", line 262, in send
chunked=self._chunked(request.headers),
File "/var/runtime/urllib3/connectionpool.py", line 641, in urlopen
_stacktrace=sys.exc_info()[2])
File "/var/runtime/urllib3/util/retry.py", line 344, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/var/runtime/urllib3/packages/six.py", line 686, in reraise
raise value
File "/var/runtime/urllib3/connectionpool.py", line 603, in urlopen
chunked=chunked)
File "/var/runtime/urllib3/connectionpool.py", line 344, in _make_request
self._validate_conn(conn)
File "/var/runtime/urllib3/connectionpool.py", line 843, in _validate_conn
conn.connect()
File "/var/runtime/urllib3/connection.py", line 316, in connect
conn = self._new_conn()
File "/var/runtime/urllib3/connection.py", line 165, in _new_conn
(self.host, self.timeout))
urllib3.exceptions.ConnectTimeoutError: (<botocore.awsrequest.AWSHTTPSConnection object at 0x7fcf62a7e128>, 'Connection to kinesisvideo.eu-west-1.amazonaws.com timed out. (connect timeout=60)')
据我了解,我的 lambda 无法连接到 https://kinesisvideo.eu-west-1.amazonaws.com/createStream,因为它位于 VPC 中。为了测试这一点,我在我的 VPC 之外创建了一个新的临时 lambda,它工作得非常好,它可以毫无问题地连接到 Kinesis Video Stream。
要解决此问题,我知道我必须创建一个终端节点,以便我的 VPC 中的 lambda 可以访问 AWS 服务,例如 Kinesis Video Streaming。我去了 VPC 终端节点控制台并创建了一个新终端节点。我选择了“com.amazonaws.eu-west-1.kinesis-streams”服务,并确保使用与我的 lambda 相同的 VPC、子网和安全组。创建端点后,我尝试再次调用 create_stream。不幸的是,我得到了相同的结果,尝试连接时超时。
所以我的问题是:是否有可能从 VPC 提供 AWS 服务?如果有,怎么做?
更新
作为对答案的回应,我现在尝试了以下方法,但仍然遇到同样的错误:
我在 VPC 中的 Lambda 具有具有所有出站权限的 SG。然后我创建了一个从 VPC SG 入站的新 SG,然后将其分配给端点。
【问题讨论】:
标签: python amazon-web-services endpoint amazon-vpc amazon-kinesis-firehose