Skip to content

Commit efb975c

Browse files
committed
Performance improvements for webhook Lambda
1 parent 21d1408 commit efb975c

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

.deploy/lambda/lib/JProfByBotStack.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export class JProfByBotStack extends cdk.Stack {
131131
compatibleRuntimes: [lambda.Runtime.JAVA_11],
132132
});
133133

134-
const lambdaWebhookTimeout = cdk.Duration.seconds(30);
134+
const lambdaWebhookTimeout = cdk.Duration.seconds(29);
135135
const lambdaWebhook = new lambda.Function(this, 'jprof-by-bot-lambda-webhook', {
136136
functionName: 'jprof-by-bot-lambda-webhook',
137137
runtime: lambda.Runtime.JAVA_11,
@@ -140,6 +140,7 @@ export class JProfByBotStack extends cdk.Stack {
140140
layerLibfontconfig,
141141
],
142142
timeout: lambdaWebhookTimeout,
143+
maxEventAge: cdk.Duration.minutes(5),
143144
retryAttempts: 0,
144145
memorySize: 512,
145146
code: lambda.Code.fromAsset('../../launchers/lambda/build/libs/jprof_by_bot-launchers-lambda-all.jar'),
@@ -163,6 +164,10 @@ export class JProfByBotStack extends cdk.Stack {
163164
},
164165
});
165166

167+
(lambdaWebhook.node.defaultChild as lambda.CfnFunction).snapStart = {
168+
applyOn: 'PublishedVersions'
169+
};
170+
166171
const lambdaDailyUrbanDictionary = new lambda.Function(this, 'jprof-by-bot-lambda-daily-urban-dictionary', {
167172
functionName: 'jprof-by-bot-lambda-daily-urban-dictionary',
168173
runtime: lambda.Runtime.JAVA_11,
@@ -233,7 +238,7 @@ export class JProfByBotStack extends cdk.Stack {
233238

234239
api.root
235240
.addResource(props.telegramToken.replace(':', '_'))
236-
.addMethod('POST', new apigateway.LambdaIntegration(lambdaWebhook));
241+
.addMethod('POST', new apigateway.LambdaIntegration(lambdaWebhook.currentVersion));
237242

238243
new cdk.CfnOutput(this, 'URL', {
239244
value: api.deploymentStage.urlForPath()

launchers/lambda/src/main/kotlin/by/jprof/telegram/bot/launchers/lambda/JProf.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import kotlinx.serialization.ExperimentalSerializationApi
2121
import kotlinx.serialization.json.Json
2222
import org.apache.logging.log4j.LogManager
2323
import org.koin.core.component.KoinComponent
24-
import org.koin.core.component.inject
24+
import org.koin.core.component.get
2525
import org.koin.core.context.startKoin
2626

2727
@PreviewFeature
@@ -59,8 +59,8 @@ class JProf : RequestHandler<APIGatewayV2HTTPEvent, APIGatewayV2HTTPResponse>, K
5959
}
6060
}
6161

62-
private val json: Json by inject()
63-
private val pipeline: UpdateProcessingPipeline by inject()
62+
private val json: Json = get()
63+
private val pipeline: UpdateProcessingPipeline = get()
6464

6565
override fun handleRequest(input: APIGatewayV2HTTPEvent, context: Context): APIGatewayV2HTTPResponse {
6666
logger.debug("Incoming request: {}", input)

0 commit comments

Comments
 (0)