-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sls): added example for nestjs (#394)
- Loading branch information
Showing
18 changed files
with
8,101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module.exports = { | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: 'tsconfig.json', | ||
tsconfigRootDir: __dirname, | ||
sourceType: 'module', | ||
}, | ||
plugins: ['@typescript-eslint/eslint-plugin'], | ||
extends: [ | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:prettier/recommended', | ||
], | ||
root: true, | ||
env: { | ||
node: true, | ||
jest: true, | ||
}, | ||
ignorePatterns: ['.eslintrc.js'], | ||
rules: { | ||
'@typescript-eslint/interface-name-prefix': 'off', | ||
'@typescript-eslint/explicit-function-return-type': 'off', | ||
'@typescript-eslint/explicit-module-boundary-types': 'off', | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# compiled output | ||
dist | ||
node_modules | ||
.serverless | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
pnpm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# OS | ||
.DS_Store | ||
|
||
# Tests | ||
coverage | ||
.nyc_output | ||
|
||
# IDEs and editors | ||
.idea | ||
.project | ||
.classpath | ||
.c9/ | ||
*.launch | ||
.settings/ | ||
*.sublime-workspace | ||
|
||
# IDE - VSCode | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
FROM public.ecr.aws/docker/library/node:18.19-slim as builder | ||
RUN npm i -g pnpm | ||
|
||
WORKDIR /app | ||
|
||
COPY . . | ||
RUN pnpm install && pnpm run build | ||
|
||
FROM public.ecr.aws/docker/library/node:18.19-slim as runner | ||
COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.8.1 /lambda-adapter /opt/extensions/lambda-adapter | ||
|
||
ENV PORT=8080 NODE_ENV=production | ||
ENV AWS_LWA_ENABLE_COMPRESSION=true | ||
|
||
WORKDIR ${LAMBDA_TASK_ROOT} | ||
COPY --from=builder /app/package.json ./package.json | ||
COPY --from=builder /app/dist ./dist | ||
COPY --from=builder /app/node_modules ./node_modules | ||
|
||
CMD [ "node", "dist/main.js" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# NestJS Example with Serverless Framework | ||
|
||
Basic example of using the `aws-lambda-web-adapter` package with the NestJS framework, and the Serverless Framework version 3. | ||
|
||
## Overview | ||
|
||
The article ["Container Image Support for AWS Lambda"](https://www.serverless.com/blog/container-support-for-lambda) on the Serverless Framework blog introduces the ability to use container images with AWS Lambda, allowing developers to have full control over the execution environment and access to custom runtimes and libraries. | ||
|
||
## Getting Started | ||
|
||
Follow these steps to get the example up and running: | ||
|
||
1. Install the project dependencies using pnpm / npm: | ||
|
||
```bash | ||
pnpm install | ||
``` | ||
|
||
2. Deploy the application using the Serverless Framework: | ||
|
||
```bash | ||
serverless deploy | ||
``` | ||
|
||
This command will deploy the application to your AWS account using the Serverless Framework and create the necessary AWS Lambda function. | ||
|
||
3. Test the endpoint: | ||
|
||
Once the deployment is complete, the Serverless Framework will provide you with the endpoint URL. You can test the endpoint by sending an HTTP request to that URL. You should receive a "Hello, World!" response. | ||
|
||
|
||
To tear down the app, use: | ||
|
||
```bash | ||
serverless remove | ||
``` | ||
|
||
This command will performs the following actions: | ||
- Deletes the deployed AWS Lambda functions and associated resources. | ||
- Cleans up any event sources or triggers associated with the functions. | ||
- Deletes any additional resources provisioned by the Serverless Framework, such as AWS CloudFormation stacks or other infrastructure components. | ||
|
||
## Author | ||
- [Lafif Astahdziq](https://lafif.me) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/nest-cli", | ||
"collection": "@nestjs/schematics", | ||
"sourceRoot": "src", | ||
"compilerOptions": { | ||
"deleteOutDir": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{ | ||
"name": "serverless-nestjs", | ||
"version": "0.0.1", | ||
"description": "", | ||
"author": "", | ||
"private": true, | ||
"license": "UNLICENSED", | ||
"scripts": { | ||
"build": "nest build", | ||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", | ||
"start": "nest start", | ||
"start:dev": "nest start --watch", | ||
"start:debug": "nest start --debug --watch", | ||
"start:prod": "node dist/main", | ||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", | ||
"test": "jest", | ||
"test:watch": "jest --watch", | ||
"test:cov": "jest --coverage", | ||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", | ||
"test:e2e": "jest --config ./test/jest-e2e.json" | ||
}, | ||
"dependencies": { | ||
"@nestjs/common": "^10.0.0", | ||
"@nestjs/core": "^10.0.0", | ||
"@nestjs/platform-express": "^10.0.0", | ||
"reflect-metadata": "^0.1.13", | ||
"rxjs": "^7.8.1", | ||
"serverless": "^3.38.0" | ||
}, | ||
"devDependencies": { | ||
"@nestjs/cli": "^10.0.0", | ||
"@nestjs/schematics": "^10.0.0", | ||
"@nestjs/testing": "^10.0.0", | ||
"@types/express": "^4.17.17", | ||
"@types/jest": "^29.5.2", | ||
"@types/node": "^20.3.1", | ||
"@types/supertest": "^6.0.0", | ||
"@typescript-eslint/eslint-plugin": "^6.0.0", | ||
"@typescript-eslint/parser": "^6.0.0", | ||
"eslint": "^8.42.0", | ||
"eslint-config-prettier": "^9.0.0", | ||
"eslint-plugin-prettier": "^5.0.0", | ||
"jest": "^29.5.0", | ||
"prettier": "^3.0.0", | ||
"source-map-support": "^0.5.21", | ||
"supertest": "^6.3.3", | ||
"ts-jest": "^29.1.0", | ||
"ts-loader": "^9.4.3", | ||
"ts-node": "^10.9.1", | ||
"tsconfig-paths": "^4.2.0", | ||
"typescript": "^5.1.3" | ||
}, | ||
"jest": { | ||
"moduleFileExtensions": [ | ||
"js", | ||
"json", | ||
"ts" | ||
], | ||
"rootDir": "src", | ||
"testRegex": ".*\\.spec\\.ts$", | ||
"transform": { | ||
"^.+\\.(t|j)s$": "ts-jest" | ||
}, | ||
"collectCoverageFrom": [ | ||
"**/*.(t|j)s" | ||
], | ||
"coverageDirectory": "../coverage", | ||
"testEnvironment": "node" | ||
} | ||
} |
Oops, something went wrong.