[英]AWS Lex bot calling a lambda function in fulfilment section of the lex bot, I don't see a place to call the lambda function
I created a lex bot to call weather API from a lambda. The lambda works fine giving the temperature of the city.我创建了一个 lex 机器人来从 lambda 调用天气 API。lambda 可以很好地给出城市的温度。
I am able to call a lambdb from lex bot thanks to for the help from "Reegz"感谢“Reegz”的帮助,我能够从 lex bot 调用 lambdb
Now I get this message "intent findingweather is fulfilled" instead of getting the weather of the city.现在我收到这条消息“intent findingweather is fulfilled”而不是获取城市的天气。 The lambda when I test, works fine, I provide the city name and lambda brings the temperature
我测试时的 lambda 工作正常,我提供城市名称和 lambda 带来温度
import json
import boto3
from pprint import pprint
import urllib3
def weatherfunc(city_name):
api_key = '9100010fc2b045080a7exxf42051e547bdxx'
base_url = 'http://api.openweathermap.org/data/2.5/weather?'
finalurl = base_url + 'appid=' + api_key + '&q=' + city_name
httprequest = urllib3.PoolManager()
response = httprequest.request('GET',finalurl)
#pprint(response.data)
weather_status = json.loads(response.data.decode('utf-8'))
return weather_status["main"]["temp"]
def lambda_handler(event, context):
city = event['City']
a = weatherfunc(city)
Yeah, Lex V2's console is a little less intuitive when it comes to adding Lambda support to your Lex bot.是的,在向 Lex 机器人添加 Lambda 支持时,Lex V2 的控制台不太直观。
Unlike with Lex V1, in V2 you can only associate one Lambda function for fulfillment to your bot.与 Lex V1 不同,在 V2 中,您只能将一个 Lambda function 关联到您的机器人。
To associate the Lambda function with your Bot, do the following:-要将 Lambda function 与您的机器人相关联,请执行以下操作:-
Given the updated state of the question, please see below for my answers.鉴于问题的更新 state,请参阅下面的答案。
In order to make effective use of Lambda functions to power your Lex bot, you need to pay close attention to the Lex V2 Developer Guide .为了有效地使用 Lambda 功能为您的 Lex 机器人提供动力,您需要密切关注Lex V2 开发人员指南。
Specifically, you need to take a close look at the input that your Lambda function receives from Lex and that your Lambda response matches the format that Lex expects.具体来说,您需要仔细查看您的 Lambda function 从 Lex 接收的输入,并且您的 Lambda 响应与 Lex 期望的格式匹配。
Have a look through this workshop and its sample code to see how to correctly work with Lex's input and output formats.查看此研讨会及其示例代码,了解如何正确使用 Lex 的输入和 output 格式。
Try to add this permission to your lambda尝试将此权限添加到您的 lambda
{
action: "lambda:InvokeFunction",
principal: new iam.AnyPrincipal(),
}
If it works, you can limit your principal later on如果有效,您可以稍后限制您的本金
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.