Coder Social home page Coder Social logo

s3-image-gallery's Introduction

A Serverless Typescript Template With Docker Development Environment

https://aws.plainenglish.io/a-serverless-typescript-template-with-docker-development-environment-1f6e6683294

Notes

  • Use dc up to start the server
  • Environment variables to pass through to the app have to be duplicated in the serverless config
  • Need to add to hosts file:
    127.0.0.1 s3-image-upload.s3
    

Template features

This template has been generated using the aws-nodejs-typescript template from the Serverless framework.

Some personal modifications are:

  • Use docker to build a local development environment(HTTP server, DynamodDB, Dynamodb admin UI)
  • Use jest to implement unit test
  • Use movies data to implement example API endpoints

Project structure

The project codebase is mainly located within the src folder.
This folder is divided in:

  • functions --- Containing code base and configuration for your lambda functions and apis
  • libs --- Containing utility shared code base between your lambdas
  • repositories --- Containing DynamoDB repositories code base
.\
├── docker\
│   └── dynamodb                             # Dynamodb mounted data folder\
├── migrations                               # Migration folder\
│   └── movies                               # `Movie` migration folder\
│       ├── index.ts                         # `Movie` migration script\
│       └── movies.json                      # `Movie` migration data\
├── src\
│   ├── functions                            # Lambdas and api configuration\
│   │   └── movies                           # `Move` manager folder\
│   │       ├── index.ts                     # `Move` lambda function configuration\
│   │       ├── movie.controller.spec.ts     # `Movie` controller spec\
│   │       ├── movie.controller.ts          # `Movie` controller\
│   │       ├── movie.router.ts              # `Movie` api router\
│   │       ├── movie.service.ts             # `Movie` service\
│   │       └── movie.services.spec.ts.      # `Movie` service spec\
│   ├── libs                                 # Shared utility folder\
│   │   ├── api-gateway.spec.ts              # Api Gateway utility spec\
│   │   ├── api-gateway.ts                   # Api Gateway utility\
│   │   ├── app.error.ts                     # Application error class\
│   │   ├── ddb-doc.spec.ts                  # DynamoDB document client spec\
│   │   ├── ddb-doc.ts                       # DynamoDB document client utility\
│   │   ├── handler-resolver.spec.ts         # Lambda function handler path resolver spec\
│   │   ├── handler-resolver.ts              # Lambda function handler path resolver\
│   │   ├── helpers.spec.ts                  # Helper spec\
│   │   └── helpers.ts                       # Helper functions\
│   └── repositories                         # Repositories folder\
│       ├── base.repository.spec.ts          # Base repository spec\
│       ├── base.repository.ts               # Base repository\
│       └── movie.repository.ts              # Movie repository\
├── Dockerfile                               # NodeJS environment dockerfile\
├── README.md\
├── api.http                                 # Http request examples\
├── docker-compose.yml                       # Application service docker compose file\
├── http-client.env.json                     # Variable for `api.http`\
├── jest.config.js                           # Jest configurations\
├── nodemon.json                             # Nodemon configuration\
├── package-lock.json                        # Package lock file\
├── package.json                             # Project package.json file\
├── serverless.template.yml                  # Serverless template definition\
├── serverless.ts                            # Serverless configurations\
├── tsconfig.build.json                      # Typescript configurations for bulding\
├── tsconfig.json                            # Typescript configurations for testing and IDE features\
└── tsconfig.paths.json                      # Typescript paths configuration

Dependencies packages

None

Dev-Dependency packages

Installation/deployment instructions

  • Run npm install to install the project dependencies
  • Run npm run deploy to deploy the project stack to AWS

Locally

Make sure your docker service is already started and docker-compose is available.

Run the following command:

  • docker-compose up

If you can see something like Server ready: <http://0.0.0.0:4000> 🚀 this means the local service is ready.

In another terminal window, let's run the migration command:

  • npm run migrate:movies

Now you can try all APIs that are defined in api.http , example:

curl 'http://0.0.0.0:4000/movies/2002'

It will return a list of movies in 2002.

Run unit test

  • Run npm run test to run all unit test
  • Run npm run test:coverage to run the test and generate a coverage report

How to start with this template?

You can clone this project from Github and modifie it.

Or you can use serverless command to create a new project with the custom template:

serverless create \
  --template-url https://github.com/codetheworld-io/aws-node-http-api-docker-starter \
  --path myService

s3-image-gallery's People

Contributors

paullessing avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.