1. 17
    Create a DynamoDB table with AWS CDK
    2m 10s
⚠️ This lesson is retired and might contain outdated information.

Create a DynamoDB table with AWS CDK

Tomasz Łakomy
InstructorTomasz Łakomy
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 6 months ago

Amazon DynamoDB is a fully managed non-relational (NoSQL) database service that provides fast and predictable performance with seamless scalability.

In other words - DynamoDB is entirely managed by AWS (so it's scaled for us, even if our startup has millions of users), it's a NoSQL database so we don't have to start by defining a detailed schema like in a relational database and it's used by companies like AirBnB, Lyft and Samsung in production.

In this quick lesson we're going to learn how to create a brand new DynamoDB table from scratch with AWS CDK.

Instructor: [0:00] In order to start the todos in our app, we are going to need the database. For that, we are going to use Amazon DynamoDB. DynamoDB is a fast and flexible NoSQL database for any scale.

[0:09] What that means is that we can start small without having to write a detailed schema because it is a NoSQL database. Also, DynamoDB is a fully managed service. AWS is responsible for delivering a single digit millisecond performance at any scale and we are going to be responsible for putting data in our database.

[0:25] Let's go back to our todo backend construct and we are going to create a new DynamoDB table. First, open up the terminal and run npm install --save @aws-cdk/aws-dynamodb. Hit Enter and next we are going to import * as dynamodb from '@aws-cdk/aws-dynamodb'.

[0:42] In order to create a new table, I'm going to do new dynamodb.table. The table is going to take three arguments. The first one is the scope, which I'm going to set to this, as usual. The second argument, the id, I'm going to set it to todo-database. The third one are the props.

[0:57] The only prop that is required is the partition key. Our partition key in DynamoDB is a key that uniquely identifies each item in a DynamoDB table. As we can see, over here, a partition key is an object with a name and a type.

[1:09] The first up is the name of the attribute, I'm going to call it an id. The second one, the type, I'm going to set it to DynamoDB AttributeType string. Every single todo in our todo-database is going to have a unique id. Next, open up the terminal and run cdk deploy in order to deploy the stack to AWS.

[1:27] After it's done, we can see our table in CloudFormation. Let's go to Services, search for CloudFormation, click over here. Next up, click on our stack, and in the Resources section, we can search for Dynamo.

[1:37] Here we can see our brand new DynamoDB table. Click on it in order to go to DynamoDB Console. We can see that our table is completely empty. To make sure that everything is fine, let's go ahead and create a new item. I'm going to set the id to 123.

[1:49] Next up, I'm going to append a new property. It's going to be a string, a field of todo, and a value of "Create a DynamoDB table with CDK." I'm going to append one more thing. This is going to be a Boolean. The field name is going to be, is-complete, and the value is going to be set-to-true. If I save that we are going to be able to see our todo item created in our todo-table.

egghead
egghead
~ 10 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