jhairssteven / SAM-DynamoDB

AWS SAM example with DynamoDB running on local docker container

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Serverless Application Model (SAM) with DynamoDB and Docker

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.

Prerequisites

Configuration

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

Running the application

  1. Update NODE_ENV='development'in the .env file

  2. Run the DynamoDB container in detached mode

    src/database$ docker compose up -d
  3. Run the application with

    SAM-DynamoDB$ sam local start-api --docker-network dynamodb_network
  4. 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

Unit testing

  1. Run the DynamoDB container in detached mode

    src/database$ docker compose up -d
  2. To run unit tests and mockups, update NODE_ENV='test' in the .env file and execute the command

    src$ npm run test

About

AWS SAM example with DynamoDB running on local docker container

License:MIT License


Languages

Language:JavaScript 100.0%