Skip to content

Commit

Permalink
Adding warmer
Browse files Browse the repository at this point in the history
  • Loading branch information
Yorty Ruiz Hernandez committed Jan 22, 2024
1 parent ebec17b commit e630407
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions apps/buildnumbr/src/lambda.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Callback, Context, Handler } from 'aws-lambda';
import serverless from 'serverless-http';
import { bootstrapApp } from './bootstrap';
import { Logger } from 'nestjs-pino';

let logger: Logger;

async function bootstrap(): Promise<Handler> {
const app = await bootstrapApp();
await app.init();
const expressApp = app.getHttpAdapter().getInstance();
logger = app.get(Logger);
return serverless(expressApp);
}

Expand All @@ -19,5 +23,9 @@ export const handler: Handler = async (
if (!bootstrappedHandler) {
bootstrappedHandler = await bootstrap();
}
if (event.source === 'serverless-plugin-warmup') {
logger?.log('WarmUp - Lambda is warm!');
return 'Lambda is warm!';
}
return bootstrappedHandler(event, context, callback);
};
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"prettier-plugin-organize-imports": "^3.2.4",
"serverless-domain-manager": "^7.3.3",
"serverless-dynamodb-autoscaling": "^0.6.2",
"serverless-plugin-warmup": "^8.3.0",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"terser-webpack-plugin": "^5.3.10",
Expand Down
10 changes: 10 additions & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ frameworkVersion: '3'
plugins:
- serverless-dynamodb-autoscaling
- serverless-domain-manager
- serverless-plugin-warmup

custom:
tableName: 'projects-table'
warmup:
default:
enabled: true
prewarm: true
events:
- schedule: rate(5 minutes)
customDomains:
domainName: 'buildnumbr.com'
basePath: ''
Expand Down Expand Up @@ -54,6 +61,9 @@ functions:
handler: dist/lambda.handler
events:
- httpApi: '*'
warmup:
default:
enabled: true

resources:
Resources:
Expand Down

0 comments on commit e630407

Please sign in to comment.