question

newuser-64a41272-f9be-4eda-8d84-71a5b807515c avatar image
newuser-64a41272-f9be-4eda-8d84-71a5b807515c asked ·

Connecting dynamo db table with custom Alexa skill

Hi There,

I am working on custom alexa skill and i am getting errors in connecting the table in dynamodb with lambda in node js.Please help me with a reference.

alexa skills kitlambdaawsdynamodb
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Aardvark avatar image
Aardvark answered ·

This is a snippet of code I wrote to retrieve a value from one of DynamoDB tables and then update the record:

const AWS = require("aws-sdk");
const AWSregion = "us-east-1";
AWS.config.update({ region: AWSregion });

const DYNAMODB_TABLE_NAME = "My Dynamo Table";
const DynamoDB = new AWS.DynamoDB();

const id = "My Id";

let params = {
    Key: {
        "id": {
            S: id
        }
    },
    TableName: DYNAMODB_TABLE_NAME
};

DynamoDB.getItem(params, (err, data) => {
    if (err) {
        console.log(err, err.stack); // an error occurred
    }
    else {
        // I have a value in a field called "update". The retrieved data is in
        // data.Item.update.S

        const oldValue = data.Item.update.S;
        
        // Update the value in "update" for "id":
        const newValue = "New Data";
        params = {
            Item: {
                "id": {
                    S: id
                },
                "update": {
                    S: newValue
                }
            },
            TableName: DYNAMODB_TABLE_NAME
        };

        DynamoDB.putItem(params, (err, data) => {
            if (err) {
                console.log(err, err.stack); // an error occurred
            }
            else {
                // Update was successful
            }
        });
    }
});
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Aardvark avatar image
Aardvark answered ·

Have you granted your Lambda function access to DynamoDB by creation a role in IAM?

10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

newuser-64a41272-f9be-4eda-8d84-71a5b807515c avatar image
newuser-64a41272-f9be-4eda-8d84-71a5b807515c answered ·

Yes i have done that.I need the code to fetch the data which i am unable to do

10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

newuser-64a41272-f9be-4eda-8d84-71a5b807515c avatar image
newuser-64a41272-f9be-4eda-8d84-71a5b807515c answered ·

Thanks a lot

10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

newuser-6065c9b0-0bbe-4dd6-87c3-3e3aabec549b avatar image
newuser-6065c9b0-0bbe-4dd6-87c3-3e3aabec549b answered ·

Where is the connection between dynamodb with alexa? the code is mostly just dynamodb.


1 comment
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hello and thank you for your message.

As @Aardvark mentioned on their reply, this is just as snippet. You need to add it to your already working skill endpoint in order to have it connect to Alexa.

Regards,
Barry

0 Likes 0 ·