0
votes

I'm completely new with AWS Lex and AWS Lambda, so it's a beginner question. I'm trying to create a bot that helps a user choose bikes. The first question is what type of bike the user needs and the answers are men/women/unisex/kids.

I'm trying to write a lambda validation function so that the bot will tell the user when the choice he entered is none of those mentioned above. The error I receieve is:

An error has occurred: Invalid Lambda Response: Received error response from Lambda (LambdaRequestId: 471e1df7-034c-46e7-9154-23de79cb16cf; Error: Unhandled)

And this is the code:

import json

def get_slots(intent_request):
    return intent_request['currentIntent']['slots']

def valid_bike_type(intent_request):
    bike_type=get_slots(intent_request)['BikeType']
    bike_types_lst = ['men', 'women', 'unisex', 'kids']
    if bike_type is not None and bike_type.lower() not in bike_types_lst:
        return build_validation_result(False, 'BikeType', 'We only have bikes for Men/Women/Unisex/Kids.')
    return build_validation_result(True, None, None)   
    
def dispatch(intent_request):
    intent_name = intent_request['currentIntent']['name']
    if intent_name == 'WelcomeIntent':
        return valid_bike_type(intent_request)
    raise Exception('Intent with name' + intent_name + ' not supported.')

def lambda_handler(event, context):
    return dispatch(event)

Thank you very much for any help!

2

2 Answers

2
votes

You can just use print as you would usually do on your workstation, e.g.:

def lambda_handler(event, context):
    print(event)
    return dispatch(event)

The outcome of print, or any other function that prints to stdout, will be in CloudWatch Logs as explained in AWS docs:

Lambda automatically integrates with CloudWatch Logs and pushes all logs from your code to a CloudWatch Logs group associated with a Lambda function, which is named /aws/lambda/.

For Lex, you can also check documentation about Lambda's input and output, or check avaiable blueprints.

0
votes

found some information on AWS docs about unhandled errors:

I would check first the lambda settings: Memory and Timeout (as the default is only 3 sec).

You can edit these settings using AWS console, in the lambda configuration, under the 'Basic Settings' tab.

enter image description here