Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I can't find callback parameter in python lambda handler

I'm studying for aws lambda - lex and I found coffee bot sample code with node.js.

// --------------- Main handler -----------------------
// --------------- in node.js -----------------------

// Route the incoming request based on intent.
// The JSON body of the request is provided in the event slot.

exports.handler = (event, context, callback) => {
    try {
        dispatch(event, (response) => callback(null, response));
    } catch (err) {
        callback(err);
    }
};

I want use callback parameter but i can't find it in python

// --------------- Main handler -----------------------
// --------------- in python -----------------------

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

# >>> this handler doesn't include callback <<<

If you need, compare both about

python docs vs node.js docs


Actually I want to get this function (build message to lex)

callback(elicitSlot(outputSessionAttributes, intentRequest.currentIntent.name, slots, 'BeverageType', 
                buildMessage('Sorry, but we can only do a mocha or a chai. What kind of beverage would you like?'), 
                buildResponseCard("Menu", "Today's Menu", menuItem)));

full sample code is here (https://github.com/awslabs/amz-ai-building-better-bots/blob/master/src/index.js)

anyone can help me?

like image 675
mgcation Avatar asked Oct 15 '17 04:10

mgcation


People also ask

How do you pass parameters in Lambda function in Python?

A Python lambda function behaves like a normal function in regard to arguments. Therefore, a lambda parameter can be initialized with a default value: the parameter n takes the outer n as a default value. The Python lambda function could have been written as lambda x=n: print(x) and have the same result.

How do I add a handler in Lambda?

This function handler name reflects the function name ( lambda_handler ) and the file where the handler code is stored ( lambda_function.py ). To change the function handler name in the Lambda console, on the Runtime settings pane, choose Edit.

What two arguments does a Python Lambda handler function require?

handler function will be executed each time a Lambda function is triggered. Handler takes two required arguments: an event object and a context object and an optional callback object .


1 Answers

Using callbacks is a pattern commonly-used in NodeJS for managing asynchronous execution. You don't need it in Python (for this specific use-case).

This snippet in NodeJS...

callback(null, response)

is equivalent to

return response

in Python.

like image 137
Noel Llevares Avatar answered Sep 21 '22 06:09

Noel Llevares