Learn
DynamoDB
Add DynamoDB Table to Lambda Function

Before you can save something to DynamoDB, you need to create a table. A database table is a space for storing a user’s information.

The Alexa NodeJS SDK makes it simple to create a database table from within the Lambda function — it just takes one line of code:

alexa.dynamoDBTableName = 'YourTableName';

We will add this line of code in the exports.handler method since this is the first method that is executed when a user opens an Alexa skill, and is a good place to make sure our database table is ready for reading and writing.

The first time the code above is called, Alexa will create the table. Subsequent calls will make the table available for reading and writing.

Also, you don’t need to worry about the notion of different users, because the Alexa SDK handles that by creating a row for each unique user.

Instructions

1.

Add a DynamoDB table to the exports.handler() function, with the table name 'CodecademyFlashcards'.

Make sure to add it before the line: alexa.execute();, or else the rest of the code will run and the table will not be created.

Folder Icon

Take this course for free

Already have an account?