- Install nvm and install node version 14 (reference: https://github.com/nvm-sh/nvm#installing-and-updating)
- Install docker (reference: https://docs.docker.com/engine/install/ubuntu/)
- Install Jest Runner, TSLint and SonarQube plugin on your IDE
- Clone the boiler plate by
git clone https://github.com/cjchua1989/aws-lambda.git
and runnpm install
- Install serverless via
npm install -g serverless@2.43.1
- Install
ts-node
, vianpm install -g typescript ts-node
- Copy
.env.example
to.env
- Edit
API_SECRET=[generate a random string]
This is how the files of the framework are organized.
code_templates
- Where the code template is storeddocs
- Holds the system documentationsenvironment
- Holds the Dockerfiles and mysql database data volumemigrations
- Migration files to update the database structuresrc
- Where the magic happenssrc\libs
- Holds the system librariessrc\models
- System data modelssrc\repositories
- System repositories to query models from databasesrc\services
- System services when logic happenssrc\functions
- Stores the lambda functionssrc\functions\apis
- Stores the api lambda functionssrc\functions\crons
- Stores the cron lambda functionssrc\functions\events
- Stores the events lambda functionssrc\functions\middlewares
- Function that handles token validation.env.example
- Environment file templatebuildspec.yml
- Build script for deploymentcustom.yml
- Connect the environment variable to the functionsdocker-compose.yml
- Local environment configuration filemigrations.js
- Execute the migration files to the sync the databasesresources.yml
- API Gateway response structureserverless-api.yml
- serverless.yml for the Application APIsserverless-crons.yml
- serverless.yml for Cron functionsserverless-events.yml
- serverless.yml for Event functionsartisan.ts
- Helper bash script to generate code template
These are the commands that can help automate the generation of the files of the framework.
ts-node artisan.ts make:migration <table_name>
- Generate a new migration file and store it on the migrations folderts-node artisan.ts make:event <function_name>
- Generate an event function templatets-node artisan.ts make:api <function_name>
- Generate an api function templatets-node artisan.ts make:cron <function_name>
- Generate a cron function templatets-node artisan.ts make:model <model_name>
- Generate a model code templatets-node artisan.ts make:repository <repository_name>
- Generate a repository code template and model code template if not existingts-node artisan.ts dynamo:model <model_name>
- Generate a dynamodb model code templatets-node artisan.ts dynamo:repository <repository_name>
- Generate a dynamodb repository code template and dynamodb model code template if not existingts-node artisan.ts make:service <service_name>
- Generate a service code templatets-node artisan.ts swagger:request <name>
- Generate a swagger request definition filets-node artisan.ts swagger:response <name>
- Generate a swagger response definition filets-node artisan.ts swagger:path <name>
- Generate a swagger path file
These are some of the base npm commands that you can use on each project, you can add more custom commands through the package.json.
npm run start
- Initialize your local environment with the use of dockernpm run stop
- Stop your local environmentnpm run swagger:build
- Build the swagger documentationnpm run lint
- Run tslint to clean codesnpm run serve:app
- Run the serverless offline to test application apinpm run migrate
- Execute all the new migration filesnpm run migrate:rollback
- Rollback all migrationsnpm run migrate:refresh
- Refresh the database by rolling back all migration and remigrating it allnpm run test
- Run the unit testing