简体   繁体   English

Alexa 开发人员控制台 - DynamoDB

[英]Alexa Developer Console - DynamoDB

Brand new to AWS, unsure how to proceed...全新的 AWS,不确定如何继续...

Goal: Use a skill to store data using DynamoDB.目标:使用技能使用 DynamoDB 存储数据。 Reference that data later using Javascript from a webpage.稍后使用网页中的 Javascript 引用该数据。

Problem: In the Alexa developer console ( https://developer.amazon.com/ ), I have my skill code and I have a built-in database (database button from the Code tab).问题:在 Alexa 开发者控制台 ( https://developer.amazon.com/ ) 中,我有我的技能代码和内置数据库(代码选项卡中的数据库按钮)。 When navigating to that database, I have no permissions to do anything (like get an API key for my webpage).导航到该数据库时,我无权执行任何操作(例如为我的网页获取 API 密钥)。 I've created my own account ( https://console.aws.amazon.com/ ) where I have a DynamoDB that I can modify, get a key for, etc. but I am unsure how to link it to my skill.我已经创建了自己的帐户 ( https://console.aws.amazon.com/ ),其中有一个 DynamoDB,我可以对其进行修改、获取密钥等,但我不确定如何将其与我的技能相关联。

Thanks in advance for any help.在此先感谢您的帮助。

My suggestion is to follow the following steps:我的建议是按照以下步骤操作:

Add a new file called dbHelpers.js in order to seperate Dynamodb functions from you skill ones.添加一个名为 dbHelpers.js 的新文件,以便将 Dynamodb 功能与您的技能分开。 In it you can set code like this:您可以在其中设置如下代码:

var AWS = require("aws-sdk");
const tableName = "questions";

var dbHelper = function () { };
var docClient = new AWS.DynamoDB.DocumentClient();

dbHelper.prototype.addProduct = (product) => {
    return new Promise((resolve, reject) => {
        const params = {
            TableName: tableName,
            Item: { 
                'name': "T-shirt"
            }
        };
        docClient.put(params, (err, data) => {
            if (err) {
                console.log("Unable to insert =>", JSON.stringify(err))
                return reject("Unable to insert");
            }
            // console.log("Saved Data, ", JSON.stringify(data));
            resolve(data);
        });
    });
}

This code is initializing DynamoDB client, with an example of creating new item to DB.此代码正在初始化 DynamoDB 客户端,以创建新项目到 DB 为例。 You can read this doc for more info https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.NodeJs.03.html .您可以阅读此文档以获取更多信息https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.NodeJs.03.html

Then in your intent, after importing the helper file and setting table name as constant, you can call it like this然后按照您的意图,在导入帮助文件并将表名设置为常量后,您可以这样调用它

  return dbHelper.getTrack('0').then((data) => {
    })

and add this to you Alexa Skill initialization并将其添加到您的 Alexa Skill 初始化中

    .withTableName(dynamoDBTableName)
    .withAutoCreateTable(true)
    .lambda();

You are missing proper IAM role.您缺少适当的 IAM 角色。 Or rather trust relationship.或者说是信任关系。

See this guide for more details: https://developer.amazon.com/en-US/docs/alexa/hosted-skills/alexa-hosted-skills-personal-aws.html有关更多详细信息,请参阅本指南: https : //developer.amazon.com/en-US/docs/alexa/hosted-skills/alexa-hosted-skills-personal-aws.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM