AWS lambda function - 'An error occured: received an error response Lambda: Handled'
Work with AWS Lex
to create a ChatBot and use Node.js
in AWS Lambda
.
Error: An error occurred: Received an error response from Lambda: Processed
Lambda function:
var aws = require('aws-sdk');
var ses = new aws.SES({region: 'us-east-1'});
exports.handler = function(event, context, callback) {
var eParams = {
Destination: {
ToAddresses: [event.currentIntent.slots.Email]
},
Message: {
Body: {
Text: {
Data: "Hi, How are you?"
}
},
Subject: {
Data: "Title"
}
},
Source: "abc@gmail.com"
};
var email = ses.sendEmail(eParams, function(err, data){
if(err)
else {
context.succeed(event);
}
});
};
How to get the correct answer from Lambda to Lex after successful execution (Email service is working correctly). I tried context.done();
it but it didn't work.
Edit 1: Tried adding below test response from AWS Documentation for LEX while still getting the same error response.
exports.handler = (event, context, callback) => {
callback(null, {
"dialogAction": {
"type": "ConfirmIntent",
"message": {
"contentType": "PlainText or SSML",
"content": "message to convey to the user, i.e. Are you sure you want a large pizza?"
}
}
});
source to share
As mentioned in the lambda-input-response-format docs, this fulfillmentState
requires a property in the response.
Another thing is, you must pass either PlainText
OR SSML
for contentType
in the response. In your case, it's simple PlainText
.
exports.handler = (event, context, callback) => {
callback(null, {
"dialogAction": {
"type": "ConfirmIntent",
"fulfillmentState": "Fulfilled", // <-- Required
"message": {
"contentType": "PlainText",
"content": "message to convey to the user, i.e. Are you sure you want a large pizza?"
}
}
});
The above code should solve your problem.
However, if you see req-res in the network tab, you get an HTTP 424 error that states a DependencyFailedException that says Amazon Lex does not have sufficient permissions to call the Lambda function " which is misleading.
source to share