Search code examples
node.jsamazon-web-servicesaws-lambdaamazon-dynamodbalexa-skills-kit

Use DynamoDB with Alexa Lambda function


Well, I am having an issue that I've been dealing with for the last 2 days and still seem to have no progress on.

Basically, I am trying to develop a skill for Amazon's echo dot, but my particular skill requires the use of persistent data. I took to the docs and found information on account linking and DynamoDB, account linking seemed to complex for a simple research project so I took to DynamoDB.

I used a lambda function, and it ran fine until I put the DynamoDB table line:

alexa.dynamoDBTableName = 'rememberThisDB';

That line completely stops my skill from working and returns the following message:

The remote endpoint could not be called, or the response it returned was invalid.

I honestly have no idea how to deal with it; I am completely new to the whole AWS concept so I don't even know how to get the actual error message that the Lambda function is returning.

I changed the role and gave it the following configuration:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "logs:CreateLogGroup",
        "logs:CreateLogStream",
        "logs:PutLogEvents"
      ],
      "Resource": "arn:aws:logs:*:*:*"
    },
        {
            "Effect": "Allow",
            "Action": [
                "dynamodb:DeleteItem",
                "dynamodb:GetItem",
                "dynamodb:PutItem",
                "dynamodb:Scan",
                "dynamodb:UpdateItem"
            ],
            "Resource": "*Yes, I did put the correct ARN*"
        }
  ]
}

But that didn't really change anything, it still just returned the same error.

The issue is, I'm not doing anything at all with DynamoDB, I am simply defining the dynamoDBTableName property of the alexa object, that's it.

Yes, the DynamoDB table exists.

I feel like my head is about to blow up, so any help would be greatly appreciated.

UPDATE: Found out how to see logs, here is the latest log: Error fetching user state: ValidationException: The provided key element does not match the schema, not sure why it would give that error since I never queried anything, the only thing I did was declare the table name.


Solution

  • Just to document the resolution of the question in the comments and so that this question doesn't remain "unanswered" on SO:

    Assuming you're using the alexa-skills-kit-sdk-for-nodejs, your table should have a single userId string HASH key.

    var newTableParams = {
        AttributeDefinitions: [
            {
                AttributeName: 'userId',
                AttributeType: 'S'
            }
        ],
        KeySchema: [
            {
                AttributeName: 'userId',
                KeyType: 'HASH'
            }
        ],
        ProvisionedThroughput: {
            ReadCapacityUnits: 5,
            WriteCapacityUnits: 5
        }
    }
    

    It turned out the user did not have the appropriate schema setup for their DynamoDB table.