amazon-web-servicesboto3amazon-lex

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.

I am able to call a lambdb from lex bot thanks to for the help from "Reegz"

Now I get this message "intent findingweather is fulfilled" instead of getting the weather of the city. The lambda when I test, works fine, I provide the city name and lambda brings the temperature

enter image description here

  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)
        

Solution

  • Given the updated state of the question, please see below for my answers.

    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.

    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.

    Have a look through this workshop and its sample code to see how to correctly work with Lex's input and output formats.