A stater project for creating, setting up and deploying nestjs project to aws lambda.
This project presume that you have aws account with privilege to setup neccessary services.
First, clone the repository:
$ git clone https://github.com/tuna-date/Serverless-NestJS-MySQL-Swagger.git
Install dependency package:
$ npm install
Create enviroment file:
$ cp .env.example .env
Modify the enviroment variables in .env to match your setting.
STAGE=<YOUR STAGE>
REGION=<DEPLOYMENT REGION>
TYPEORM_CONNECTION = <YOUR CONNECTION>
TYPEORM_HOST = <DB HOST>
TYPEORM_PORT = <DB PORT>
TYPEORM_USERNAME = <DB USER>
TYPEORM_PASSWORD = <DB PASSWORD>
TYPEORM_DATABASE = <DB NAME>
Install serverless:
$ npm install -g serverless
Set up aws profile
$ serverless config credentials --provider aws --key YOUR_ACCESS_KEY --secret YOUR_SECRET_ACCESS_KEY --profile nest-test
Compile project:
$ npm run-script build
Before deploying, we can verify that serverless configuration is OK or not with:
$ sls offline start
In this project, I use:
serverless-plugin-optimizefor optimizing code before deploying.serverless-dotenv-pluginfor injecting enviroment variables from.envto lambda instance enviroment.
Deploy
$ sls deploy
While deploying, serverless may warn you about access authorities over services like APIGateway, CloudFormation, etc. Just attach the corresponding policies to those services with your aws user and continue.
After the deployment command executing complete, follow the generated endpoints and get the result:
