1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

    Deploy a new DynamoDB table to AWS using AWS SAM template

    Tomasz ŁakomyTomasz Łakomy
    awsAWS

    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.

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Discuss

    Discuss

    Transcript

    Transcript

    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.