Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/twihike/nestjs-lambda-starter
🚀 Nest framework starter with AWS Lambda
https://github.com/twihike/nestjs-lambda-starter
amplify aws aws-lambda lambda nest nestjs
Last synced: 2 days ago
JSON representation
🚀 Nest framework starter with AWS Lambda
- Host: GitHub
- URL: https://github.com/twihike/nestjs-lambda-starter
- Owner: twihike
- Created: 2020-07-12T14:21:54.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-24T04:34:41.000Z (almost 2 years ago)
- Last Synced: 2023-03-06T22:58:50.338Z (over 1 year ago)
- Topics: amplify, aws, aws-lambda, lambda, nest, nestjs
- Language: TypeScript
- Homepage:
- Size: 2.99 MB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# nestjs-lambda-starter
[![CI status](https://github.com/twihike/nestjs-lambda-starter/workflows/ci/badge.svg)](https://github.com/twihike/nestjs-lambda-starter/actions)
[NestJS](https://github.com/nestjs/nest) framework starter with AWS Lambda.
## Related projects
- [nest-starter](https://github.com/twihike/nestjs-starter)
## How to use with Amplify
Add API and Function.
```shell
cd
amplify add api
``````text
? Please select from one of the below mentioned services: REST
? Provide a friendly name for your resource to be used as a label for this category in the project: apixxxxxxxx
? Provide a path (e.g., /book/{isbn}): /api
? Choose a Lambda source Create a new Lambda function
? Provide a friendly name for your resource to be used as a label for this category in the project: examplexxxxx
? Provide the AWS Lambda function name: examplexxxxx
? Choose the function runtime that you want to use: NodeJS
? Choose the function template that you want to use: Serverless ExpressJS function (Integration with API Gateway)
? Do you want to access other resources created in this project from your Lambda function? No
? Do you want to invoke this function on a recurring schedule? No
? Do you want to edit the local lambda function now? Yes
Succesfully added the Lambda function locally
? Restrict API access Yes
? Who should have access? Authenticated users only
? What kind of access do you want for Authenticated users? create, read, update, delete
? Do you want to add another path? No
Successfully added resource apifefce8b8 locallySome next steps:
"amplify push" will build all your local backend resources and provision it in the cloud
"amplify publish" will build all your local backend and frontend resources (if you have hosting category added) and provision it in the cloud
```Configure lambda handler and environment variables.
```shell
cd /amplify/backend/function/
vi -cloudformation-template.json
``````diff
diff --git a/-cloudformation-template.json b/-cloudformation-template.json
--- a/-cloudformation-template.json
+++ b/-cloudformation-template.json
@@ -30,7 +30,7 @@
"aws:asset:property": "Code"
},
"Properties": {
- "Handler": "index.handler",
+ "Handler": "dist/index.handler",
"FunctionName": {
"Fn::If": [
"ShouldNotCreateEnvResources",
@@ -53,11 +53,16 @@
"Environment": {
"Variables" : {
"ENV": {
"Ref": "env"
},
"REGION": {
"Ref": "AWS::Region"
- }
+ },
+ "NODE_ENV": "production",
+ "TYPEORM_HOST": "your db host",
+ "TYPEORM_USERNAME": "your username",
+ "TYPEORM_PASSWORD": "your password",
+ "TYPEORM_DATABASE": "your db name"}
},
```Clone starter repository.
```shell
cd /amplify/backend/function/
rm -rf src
git clone https://github.com/twihike/nestjs-lambda-starter.git src
cd src
rm -rf .git
yarn install
```Run `amplify-push.sh` to do the following:
- Compile to JavaScript.
- Install only the production packages used by lambda.
- Run `amplify push`.```shell
# requires jq and docker
cd /amplify/backend/function//src
./scripts/amplify-push.sh
```## Running the app
```shell
# development
yarn run start# watch mode
yarn run start:dev# production mode
yarn run start:prod
```## Test
```shell
# unit tests
yarn run test# e2e tests
yarn run test:e2e# test coverage
yarn run test:cov
```## DB migration
```shell
# generate
yarn run migration:generate# show all migrations
yarn run migration:show# run
yarn run migration:run# dry run
yarn run schema:log# revert
yarn run migration:revert
```## Documentation
```shell
yarn run doc
```