Skip to content

mbc-net/mbc-todo-sample

Repository files navigation

MBC CQRS serverless framework

Description

MBC CQRS serverless framework based on Nest.

TechStack:

  • Nest

  • TypeScript

  • AWS Serverless

    • API GW
    • Lambda
    • Step Functions
    • EventBridge
    • DynamoDB
  • RDS - PostgreSQL

  • Serverless fw && Localstack for local development

Prepare

Installation

$ cp .env.local .env
$ npm install

Running the app

# development build
$ npm run build

# docker, open in other terminal session
$ npm run offline:docker

# migrate tables, open in other terminal session
$ npm run migrate

# copy dynamodb stream arn to `.env` file
      # LOCAL_DDB_MASTER_STREAM=arn:aws:dynamodb:ddblocal:000000000000:table/local-demo-master-command/stream/2024-01-02T03:07:49.349

# serverless, open in other terminal session
$ npm run offline:sls
  • After successfully running
DEBUG[serverless-offline-sns][adapter]: successfully subscribed queue "http://localhost:9324/101010101010/notification-queue" to topic: "arn:aws:sns:ap-northeast-1:101010101010:CqrsSnsTopic"
Offline Lambda Server listening on http://localhost:4000
serverless-offline-aws-eventbridge :: Plugin ready
serverless-offline-aws-eventbridge :: Mock server running at port: 4010
Starting Offline SQS at stage dev (ap-northeast-1)
Starting Offline Dynamodb Streams at stage dev (ap-northeast-1)

Starting Offline at stage dev (ap-northeast-1)

Offline [http for lambda] listening on http://localhost:3002
Function names exposed for local invocation by aws-sdk:
           * main: serverless-example-dev-main
Configuring JWT Authorization: ANY /{proxy+}

   ┌────────────────────────────────────────────────────────────────────────┐
   │                                                                        │
   │   ANY | http://localhost:3000/api/public                               │
   │   POST | http://localhost:3000/2015-03-31/functions/main/invocations   │
   │   ANY | http://localhost:3000/swagger-ui/{proxy*}                      │
   │   POST | http://localhost:3000/2015-03-31/functions/main/invocations   │
   │   ANY | http://localhost:3000/{proxy*}                                 │
   │   POST | http://localhost:3000/2015-03-31/functions/main/invocations   │
   │                                                                        │
   └────────────────────────────────────────────────────────────────────────┘

Server ready: http://localhost:3000 🚀

Helpers

# prisma command
$ npx prisma

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Before use Keycloak

Go to http://localhost:8180/admin/master/console/#/master/clients

  • create a new client

    • Client type: OpenID Connect
    • Client ID: hello-world
    • Valid redirect URIs: *
    • Web origins: *
  • go to Client scopes tab, then add new mapper

    • Mapper type: Audience
    • Name: hello-world
    • Included Client Audience: hello-world
    • Add to access token: true
  • Ref: https://www.keycloak.org/getting-started/getting-started-docker

Update frontend/aws-export.js

$ cp frontend/aws-export.local.js frontend/src/aws-export.js

Step function execution

$ aws stepfunctions --endpoint-url http://localhost:8083 start-execution --state-machine-arn arn:aws:states:ap-northeast-1:101010101010:stateMachine:foo1

Endpoints

Nestjs Debug mode

Run the following cmd to open nestjs debug mode

$ npm run start:repl

Documentation

Visit https://mbc-cqrs-serverless.mbc-net.com/ to view the full documentation.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published