This project contains source code and supporting files for a basic REST API that is deployed with SAM CLI and Docker. It includes the following files and folders.
src/controller | Contains the application controllers. |
src/database | Contains the database models and configurations. |
src/repository | Contains the ORM operations of the models. |
src/request | Contains examples of the application's requests. |
src/service | Contains external services required for the operation of the main functionalities. |
src/test | Contains mockups and unit tests for functional testing. |
template.yaml | Defines the AWS resources of the application. |
-
SAM CLI - Install the SAM CLI
-
Node.js and npm - Install Node.js
-
Docker and Docker compose - Install Docker
In the src
folder, create a .env
file with the following environment variables. Be sure to assign the corresponding values.
NODE_ENV='' #development, test
SECRET='' #jwtsupersecret
Install dependencies with
src$ npm i
-
Update NODE_ENV='development'in the .env file
-
Run the DynamoDB container in detached mode
src/database$ docker compose up -d
-
Run the application with
SAM-DynamoDB$ sam local start-api --docker-network dynamodb_network
-
You can send requests using the format of each endpoint in the request folder.
Note: To stop the DynamoDB container
src/database$ docker compose down -v
-
Run the DynamoDB container in detached mode
src/database$ docker compose up -d
-
To run unit tests and mockups, update
NODE_ENV='test'
in the.env
file and execute the commandsrc$ npm run test