在 alexa 技能中使用 aws-sdk

Use aws-sdk in alexa skill

我正在尝试开发一项 Alexa 技能,该技能可从 DynamoDB 数据库中获取信息。为了使用它,我必须导入 aws-sdk.

但是由于某种原因,当我导入它时,我的技能停止工作了。技能连开都没有。我的代码托管在 Alexa Developer Console 上。 这是发生了什么:

在测试面板中,当我输入 'Open Cricket Update'(应用程序名称)时,Alexa 的响应是“所请求技能的响应存在问题”。 只有当我导入 aws-sdk 时才会发生这种情况。

我做错了什么?

index.js

const Alexa = require('ask-sdk-core');
const AWS = require('aws-sdk');
AWS.config.update({region:'us-east-1'});

const table = 'CricketData';
const docClient = new AWS.DynamoDB.DocumentClient();

const LaunchRequestHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';
    },
    handle(handlerInput) {
        const speakOutput = 'Hello! Welcome to cricket update.';
        return handlerInput.responseBuilder
            .speak(speakOutput)
            .reprompt(speakOutput)
            .getResponse();
    }
};

package.json

{
  "name": "hello-world",
  "version": "1.1.0",
  "description": "alexa utility for quickly building skills",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Amazon Alexa",
  "license": "ISC",
  "dependencies": {
    "ask-sdk-core": "^2.6.0",
    "ask-sdk-model": "^1.18.0",
    "aws-sdk": "^2.326.0"
  }
}

您缺少 index.js 末尾的 exports.handler 块,"builds" 由您的处理程序组成的技能,例如

exports.handler = Alexa.SkillBuilders.custom()
.addRequestHandlers(LaunchRequestHandler)
.lambda();

可以找到更完整的示例here