skip to Main Content

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)
        

3

Answers


  1. Yeah, Lex V2’s console is a little less intuitive when it comes to adding Lambda support to your Lex bot.

    Unlike with Lex V1, in V2 you can only associate one Lambda function for fulfillment to your bot.

    To associate the Lambda function with your Bot, do the following:-

    • Click on "Test" from the taskbar at the bottom of the "Intents"
      screen
    • Click the settings cog in the pop-up window the opens
    • A settings pane will open to the left of the "Test" pane
    • The first block called "Lambda function – optional" is where you can select the appropriate Lambda function
    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
  3. Try to add this permission to your lambda

    {
      action: "lambda:InvokeFunction",
      principal: new iam.AnyPrincipal(),
    }
    

    If it works, you can limit your principal later on

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search