File tree Expand file tree Collapse file tree 5 files changed +996
-5
lines changed Expand file tree Collapse file tree 5 files changed +996
-5
lines changed Original file line number Diff line number Diff line change @@ -143,6 +143,15 @@ Resources:
143143 - lambda.amazonaws.com
144144
145145 Policies :
146+ - PolicyName : lambda-self-invoke
147+ PolicyDocument :
148+ Version : " 2012-10-17"
149+ Statement :
150+ - Action :
151+ - lambda:invokeFunction
152+ Effect : Allow
153+ Resource :
154+ - Fn::Sub : " arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${LambdaFunctionName}:*"
146155 - PolicyName : lambda-generic
147156 PolicyDocument :
148157 Version : " 2012-10-17"
Original file line number Diff line number Diff line change @@ -192,6 +192,16 @@ Resources:
192192 RestApiId : !Ref AppApiGateway
193193 Path : /{proxy+}
194194 Method : ANY
195+ WarmingSchedule :
196+ Type : Schedule
197+ Properties :
198+ Schedule : !If [
199+ ShouldAttachVpc,
200+ ' rate(15 minutes)' ,
201+ ' rate(5 minutes)'
202+ ]
203+ Input : ' { "warmer":true,"concurrency":3 }'
204+
195205
196206 AppSqsLambdaFunction :
197207 Type : AWS::Serverless::Function
Original file line number Diff line number Diff line change 11import "zod-openapi/extend" ;
22import awsLambdaFastify from "@fastify/aws-lambda" ;
33import init from "./index.js" ;
4+ import warmer from "lambda-warmer" ;
5+ import { type APIGatewayEvent , type Context } from "aws-lambda" ;
46
57const app = await init ( ) ;
6- const handler = awsLambdaFastify ( app , {
8+ const realHandler = awsLambdaFastify ( app , {
79 decorateRequest : false ,
810 serializeLambdaArguments : true ,
911 callbackWaitsForEmptyEventLoop : false ,
1012} ) ;
13+ const handler = async ( event : APIGatewayEvent , context : Context ) => {
14+ // if a warming event
15+ if ( await warmer ( event , { correlationId : context . awsRequestId } , context ) ) {
16+ return "warmed" ;
17+ }
18+ // else proceed with handler logic
19+ return realHandler ( event , context ) ;
20+ } ;
21+
1122await app . ready ( ) ; // needs to be placed after awsLambdaFastify call because of the decoration: https://github.com/fastify/aws-lambda-fastify/blob/master/index.js#L9
1223export { handler } ;
Original file line number Diff line number Diff line change 1717 "dependencies" : {
1818 "@aws-sdk/client-cloudfront-keyvaluestore" : " ^3.797.0" ,
1919 "@aws-sdk/client-dynamodb" : " ^3.797.0" ,
20+ "@aws-sdk/client-lambda" : " ^3.835.0" ,
2021 "@aws-sdk/client-secrets-manager" : " ^3.797.0" ,
2122 "@aws-sdk/client-ses" : " ^3.797.0" ,
2223 "@aws-sdk/client-sqs" : " ^3.797.0" ,
4950 "ioredis" : " ^5.6.1" ,
5051 "jsonwebtoken" : " ^9.0.2" ,
5152 "jwks-rsa" : " ^3.2.0" ,
53+ "lambda-warmer" : " ^2.3.0" ,
5254 "moment" : " ^2.30.1" ,
5355 "moment-timezone" : " ^0.5.48" ,
5456 "node-cache" : " ^5.1.2" ,
You can’t perform that action at this time.
0 commit comments