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?
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.
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.
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 .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With