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:
143
143
- lambda.amazonaws.com
144
144
145
145
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}:*"
146
155
- PolicyName : lambda-generic
147
156
PolicyDocument :
148
157
Version : " 2012-10-17"
Original file line number Diff line number Diff line change @@ -192,6 +192,16 @@ Resources:
192
192
RestApiId : !Ref AppApiGateway
193
193
Path : /{proxy+}
194
194
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
+
195
205
196
206
AppSqsLambdaFunction :
197
207
Type : AWS::Serverless::Function
Original file line number Diff line number Diff line change 1
1
import "zod-openapi/extend" ;
2
2
import awsLambdaFastify from "@fastify/aws-lambda" ;
3
3
import init from "./index.js" ;
4
+ import warmer from "lambda-warmer" ;
5
+ import { type APIGatewayEvent , type Context } from "aws-lambda" ;
4
6
5
7
const app = await init ( ) ;
6
- const handler = awsLambdaFastify ( app , {
8
+ const realHandler = awsLambdaFastify ( app , {
7
9
decorateRequest : false ,
8
10
serializeLambdaArguments : true ,
9
11
callbackWaitsForEmptyEventLoop : false ,
10
12
} ) ;
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
+
11
22
await 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
12
23
export { handler } ;
Original file line number Diff line number Diff line change 17
17
"dependencies" : {
18
18
"@aws-sdk/client-cloudfront-keyvaluestore" : " ^3.797.0" ,
19
19
"@aws-sdk/client-dynamodb" : " ^3.797.0" ,
20
+ "@aws-sdk/client-lambda" : " ^3.835.0" ,
20
21
"@aws-sdk/client-secrets-manager" : " ^3.797.0" ,
21
22
"@aws-sdk/client-ses" : " ^3.797.0" ,
22
23
"@aws-sdk/client-sqs" : " ^3.797.0" ,
49
50
"ioredis" : " ^5.6.1" ,
50
51
"jsonwebtoken" : " ^9.0.2" ,
51
52
"jwks-rsa" : " ^3.2.0" ,
53
+ "lambda-warmer" : " ^2.3.0" ,
52
54
"moment" : " ^2.30.1" ,
53
55
"moment-timezone" : " ^0.5.48" ,
54
56
"node-cache" : " ^5.1.2" ,
You can’t perform that action at this time.
0 commit comments