使用boto3从aws lambda调用amazon-lex时出错



我在同一个区域上发布了一个Lex-bot和一个Lambda函数。我正在尝试使用以下代码与Lambda的Lex进行交互。

import boto3 
client = boto3.client('lex-runtime')
def lambda_handler(event, context):
response = client.post_text(
botName='string',
botAlias='string',
userId='string',
# sessionAttributes={
#     'string': 'string'
# },
# requestAttributes={
#     'string': 'string'
# },
inputText='entity list'
)
return response

在测试代码时,我的lambda函数超时了。如果你还需要知道什么,请告诉我。

错误消息:

"errorMessage": "2021-04-30T07:09:45.715Z <req_id> Task timed out after 183.10 seconds"

专有网络中的Lambda,包括默认的专有网络,没有互联网接入。由于您的lambda位于默认的VPC中,它将无法连接到任何lex-runtimeAWS端点,从而导致超时。

由于lex不支持VPC端点,您的lambda访问lex-runtime的唯一方法是:

  • 将您的功能与VPC解除关联。如果你这样做,你的功能将能够连接到互联网,然后连接到lex-runtime

  • 在默认的VPC中创建一个私有子网,并设置一个NAT网关。然后将您的函数放在新的子网中。这样你的功能将能够使用NAT连接到互联网。

更多信息在:

  • 如何为连接到亚马逊专有网络的Lambda功能提供互联网访问权限

最新更新