AWS lambda函数-'发生错误:收到来自Lambda的错误响应:已处理' [英] AWS lambda function- 'An error has occurred: Received error response from Lambda: Handled'

查看:427
本文介绍了AWS lambda函数-'发生错误:收到来自Lambda的错误响应:已处理'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用AWS Lex来创建ChatBot并使用AWS Lambda中的Node.js.

Working on AWS Lex for creating a ChatBot and using the Node.js in AWS Lambda.

错误:发生错误:收到来自Lambda的错误响应: 处理

Error: An error has occurred: Received error response from Lambda: Handled

Lambda函数:

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);

            }
        });
    };

如何在成功执行后如何从Lambda获得对Lex的正确响应(电子邮件服务正常工作).我已经尝试过context.done();,但是没有成功.

How to get a proper response from Lambda to Lex after successful execution (Email Service works properly). I have tried context.done(); but it did not worked out.

尝试在 AWS LEX文档中添加以下响应测试仍然得到相同的错误响应.

Edit 1: Tried adding below response test from AWS Documentation for LEX 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?" 
} 

} 


});

推荐答案

lambda-input-response-format docs

As mentioned in the lambda-input-response-format docs here fulfillmentState property is required in the response.

另一件事是您必须在响应中为contentType传递PlainTextSSML.就您而言,它只是PlainText.

Other thing is you have to pass either PlainText OR SSML for the contentType in the response. In your case its just 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.

但是,如果您在网络标签中看到要求,您将收到HTTP错误424,其中显示 DependencyFailedException 表示 "Amazon Lex没有足够的权限来调用Lambda函数" 极具误导性.

However if you see the req-res in the network tab you would receive HTTP Error 424 which says DependencyFailedException which says "Amazon Lex does not have sufficient permissions to call a Lambda function" very misleading.

这篇关于AWS lambda函数-'发生错误:收到来自Lambda的错误响应:已处理'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆