Hey! I`m looking for a way to make my key "id" dynamic so that if I say "ten" I get the answer for my dynamodb message for the id ten! Anyone has a fix I tried a lot but everything resulted in errors!
const AWSregion = 'eu-west-1'; // us-east-1 const Alexa = require('alexa-sdk'); const AWS = require('aws-sdk'); AWS.config.update({ region: AWSregion }); exports.handler = function(event, context, callback) { var alexa = Alexa.handler(event, context); alexa.registerHandlers(handlers); alexa.execute(); }; const handlers = { 'LaunchRequest': function () { this.response.speak('Welcome! Ask yes or no question').listen('versuch es nochmal'); this.emit(':responseReady'); }, 'MyIntent': function () { var MyQuestion = this.event.request.intent.slots.MyQuestion.value; var params = { TableName: 'yesno', Key:{ "id": "one" } }; console.log('MyQuestion : ' + MyQuestion); readDynamoItem(params, myResult=>{ var say = ''; say = myResult; say = 'Deine Frage war:, ' + MyQuestion + '. Die Antwort darauf ist: ' + myResult; this.response.speak(say).listen('try again'); this.emit(':responseReady'); }); function readDynamoItem(params, callback) { var AWS = require('aws-sdk'); AWS.config.update({region: AWSregion}); var docClient = new AWS.DynamoDB.DocumentClient(); console.log('reading item from DynamoDB table'); docClient.get(params, (err, data) => { if (err) { console.error("Unable to read item. Error JSON:", JSON.stringify(err, null, 2)); } else { console.log("GetItem succeeded:", JSON.stringify(data, null, 2)); callback(data.Item.message); // this particular row has an attribute called message } }); }