Deploy a new DynamoDB table to AWS using AWS SAM template

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

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

In this quick lesson we're going to learn how to define a brand new DynamoDB table in an AWS SAM template and how to deploy it to AWS.

We're going to use the AWS::Serverless::SimpleTable resource type, specify a primary key as well as the table name, deploy it to AWS and see if we're able to add an item to our new table.

Tomasz Łakomy: [0:00] We have a serverless application model application, which is currently deploying a lambda function and also an S3 bucket. We would like to use the template in order to deploy a DynamoDB table as well. I'm going to create a new resources, which I'm going to call MyAwsomeTable, which is going to be of type AWS, serverless, SimpleTable.

[0:21] With SAM, we can either create a DynamoDB table from scratch, or we can use a SimpleTable. SimpleTable is basically a DynamoDB table with some sensible defaults built in. We'll not have to configure everything. Nevertheless, let me add some properties. I'm going to paste them in.

[0:35] We have a primary key of the name ID, which is going to have string. Every single item on this table is going to have an ID. This table is going to be called my-awesome-database. Let me fix the typo, save it, and then sam build.

[0:49] Now our stack has been created. Let's deploy it. Before the deployment, we're going to see that this deployment is going to add a new MyAwesomeTable which is of type DynamoDB table to our resources. Let's go ahead and deploy that.

[1:00] Let's review our stack in the AWS Lambda console. Go to applications, click on our stack, and right now we can see that it is going to create a function, MyBucket, and also MyAwesomeTable. Let's click on that. Here we can see our database, which currently has no items, which is by design, because it's a brand new table.

[1:18] But if we try to add a new item to this database, we're going to see that it has to have an ID which is of type string. For instance, I can add an ID, ABC, append something else. For instance, string of name, which is going to be equal to Thomas. Save this item, and we have a functioning database which was created using the AWS SAM stack deployment.

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