Intro to the DynamoDB Node.js DocumentClient

Chris Biscardi
InstructorChris Biscardi
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

The node.js DynamoDB client comes from the aws-sdk package. We cover how to set up the client with your AWS credentials as well as how to use the callback and promise versions of documentclient functions.

Instructor: [0:00] The Node.js DocumentClient for DynamoDB comes straight out of the AWS SDK. Make sure you install that.

[0:06] The first thing we need to do is update the AWS config with the region that our DynamoDB table is in, the access key that we'll use to access it and the secret access key as well. This allows us to instantiate a new AWS.DynamoDB.DocumentClient.

[0:21] We put the name of the table that we're going to be accessing in this table constant and follow the a fairly normal pattern for DynamoDB queries, which is we put the params in an object and then we pass the params in later. In this case, on the DocumentClient, we're using the get command which we'll cover again in another video.

[0:38] In this case, we've used the callback parameters, which give us error in data. If we run this script, we can see that get gives us back an object with an item key inside of it that gives us back the item. If we look for an item that doesn't exist, we don't get anything back.

[0:52] The DocumentClient also supports Promises. Now that we've created an additional function called runQuery(), because we can't use a single width syntax at the top level in a Node.js file -- this is a restriction of the Node.js async/await's [inaudible] and not the DocumentClient.

[1:05] We can run the script again and we'll see the same results with the new console.log, so we can use the DocumentClient with either a Callback-based approach or a Promise-based approach which will let us use Promises with .then or async/await.

egghead
egghead
~ 8 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today