visit
NestJS is a progressive Node. js framework that helps build server-side applications. It is built with and fully supports
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 )
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
)
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.
$ 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
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:
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'
In the src
folder, create a subfolder db
with db.service.ts
and db.module.ts
HINT: Use this shortcut
nest g resource todos --no-spec
selectREST API
press enter and typey
to generate CRUD endpoints.
Your updated file and folder structures should look like this.
yarn build && serverless offline start
Your app will be started and you should see something like this!
Also Published