🎁

12 Days of Baddass Courses sale! Get instant access to the entire egghead library of courses and lessons for 58% off.

Runs out in:
15 : 06 : 09 : 09
Join egghead, unlock knowledge.

Want more egghead? It's 58% off for a limited time only!

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock All Content for 40% Off
1×
Become a member
to unlock all features
Autoplay

    Deploy a DynamoDB table to AWS using the Serverless Framework

    Nik GrafNik Graf
    awsAWS
    javascriptJavaScript
    nodeNode.js

    The Serverless Framework uses CloudFormation to deploy our functions. Using the resources section we can deploy and configure a wide range of AWS services using raw CloudFormation definitions. In this session we demonstrate this by adding a DynamoDB table to our application.

    Your table can be seen here.

    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

    Instructor: In order to store data, we need a database. One convenient way of doing so in AWS is DynamoDB. To add a DynamoDB table, we can leverage the resources section in the serverless.yml. It allows us to add raw cloud formation resources.

    Just for clarification, why we need to nest resources twice here, it has to be nested because cloud formation also supports other keywords, like output and input. Next up, we define a resource name, and inside set the type, AWS DynamoDB table.

    In the minimum configuration, a table needs to have a couple of properties defined, the table name, the attributes used for primary and secondary indexes. In our case, we have an ID of type string. Then we add a key schema and define the attributes that make up the primary key for our table. In our case, this is the field ID.

    Keep in mind, in the table we can still store other attributes, like text or createdAt. It's not necessary to define them here. It's only mandatory to define those used for the key schema.

    Last but not least, we define the throughput capacity for read and write. In our case, one is sufficient. In case you need to scale, I recommend you to activate autoscaling for the DynamoDB table. Then we run SLS deploy, and cloud formation will set up our table.

    Let's switch over to the console. As we can see, the table exists now.