paint-brush
Using a NestJS Application with DynamoDB and Serverless Framework on AWS by@airscholar
7,319 reads
7,319 reads

Using a NestJS Application with DynamoDB and Serverless Framework on AWS

by Yusuf GaniyuJuly 21st, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

NestJS is a progressive Node.** js framework that helps build server-side applications. It is built with and fully supports TypeScript, yet still enables developers to code in pure JavaScript. The Serverless Framework is a free and open-source web framework written using Node.js. The first framework developed for building applications on AWS Lambda, a serverless computing platform provided by Amazon as a part of Amazon Web Services. In this article, I take you on a journey to fully setup your NestJS Application with a fully functional DynamoDB and Serverless.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Using a NestJS Application with DynamoDB and Serverless Framework on AWS
Yusuf Ganiyu HackerNoon profile picture


NestJS is a progressive Node. js framework that helps build server-side applications. It is built with and fully supports  (yet still enables developers to code in pure JavaScript) and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).You can read more on it here .


A lot of people are having challenges setting up Serverless Framework with DynamoDB, if you happen to fall within this category, then this is the article you have been looking for! Sit tight, relax and grab a cup of coffee while I take you on a journey to fully setup your NestJS Application with a fully functional DynamoDB and Serverless Framework :).


A little bit of housekeeping…


Amazon DynamoDB is a fully managed proprietary NoSQL database service that supports key–value and document data structures and is offered by Amazon.com as part of the Amazon Web Services portfolio. DynamoDB exposes a similar data model to and derives its name from Dynamo, but has a different underlying implementation. (Read more on DynamoDB on  or visit the )


And of course, Serverless Framework…


The Serverless Framework is a free and open-source web framework written using Node.js. Serverless is the first framework developed for building applications on AWS Lambda, a serverless computing platform provided by Amazon as a part of Amazon Web Services. (Full details )


In order to get started you on this journey, you will need to get the following installed on your machine (you can ignore this section if you have the installations done on your machine)

NestJS ()

To install NestJS on your machine, run the following commands on your terminal to get you started. You can give your project any name you want but in this article, I will be naming it nest-serverless-dynamo.


$ npm i -g @nestjs/cli
$ nest new nest-serverless-dynamo


Use the arrow key to select your desired package manager, in my case,yarn.

Now that NestJS CLI has been installed and a new project created, open up the project in your favorite IDE (mine is VsCode 😀) and let’s fire on to the juicy part.

Serverless Framework and DynamoDB

To get started with the Serverless Framework, you need to run the following commands.
$ yarn add aws-lambda aws-serverless-express express aws-sdk
$ yarn add @serverless/utils

Once the installation is done, you need to create a new file in the root directory serverless.yml



Run the following commands to sync the plugins in your serverless.yml file

$ serverless plugin install -n serverless-plugin-optimize             
$ serverless plugin install -n serverless-dynamodb-local
$ serverless plugin install -n serverless-offline

To install DynamoDB

Run this command in your root directory (the same folder where your serverless.yml is)

$ serverless dynamodb install


NOTE: At this point, your folder structure should look like this. If not, you must have skipped a step, retrace your steps before continuing!


Start your DynamoDB locally to test if you are having this error, if not, GREAT! If you are, check the solution below:


If you made it to this point, you are now a serverless guru! 😄. Do not get tired, we are almost done!


We are almost there. Navigate to the src folder and create a serverless.ts file with the content below.



You also need to create a .env file with the following keys. (NOTE: Port 6000 is the port specified in the serverless.yml file.)

IS_OFFLINE = 'true'
DYNAMODB_ENDPOINT = '//localhost:6000/shell'


We are pretty much done with the setups, let’s now focus on the app itself.


The only part left is to connect our NestJS app to Dynamo DB


In the src folder, create a subfolder db with db.service.ts and db.module.ts




Let’s create a todo module

HINT: Use this shortcut nest g resource todos --no-spec select REST APIpress enter and type y to generate CRUD endpoints.


Your updated file and folder structures should look like this.









That's it!


Run the app and sip your coffee!


yarn build && serverless offline start


Your app will be started and you should see something like this!



Testing Your app

Creating a Todo

Creating a Todo


Retrieving Todos


Updating todos


Retrieving updated todos


Deleting todos


Yes! You made it!

Thank you for reading.

Also Published


바카라사이트 바카라사이트 온라인바카라