Enabling SnapStart in AWS API Gateway with Lambda
Cold start time was a problem for PieCloud because it was adding extra latency to less frequently used APIs. We enabled SnapStart and it improved start up performance 7x at no extra cost.
Setting Up SnapStart with CDK
We use CDK to setup infrastructure. Code for enabling SnapStart using CDK. Currently only X86_64 is supported for Java.
this.function = new Function(scope, 'SampleFunction', {
functionName: 'SampleFunction',
runtime: Runtime.JAVA_11,
handler: props.handler,
code: <Code path>,
architecture: Architecture.X86_64,
memorySize: 1024,
timeout: Duration.seconds(15),
logRetention: RetentionDays.ONE_MONTH
});
const version = this.function.currentVersion;
const funcAlias = new Alias(scope, 'SampleFunctionAlias', {
aliasName: 'Prod',
version,
});
(this.function.node.defaultChild as CfnFunction).addPropertyOverride('SnapStart', {
ApplyOn: 'PublishedVersions',
});
const lambdaIntegration = new LambdaIntegration(funcAlias, <Integration options>);How To Verify SnapStart is Working
- If CloudWatch logs console shows [$LATEST] in the logs, SnapStart is NOT working because SnapStart only works for Versioned Lamda calls.
2. If CloudWatch has INIT_START in logs, SnapStart is NOT working
Get Tom Wilson’s stories in your inbox
Join Medium for free to get updates from this writer.
3. If logs show RESTORE_START, SnapStart is working.
Enabling SnapStart Manually
- Create Alias for Lambda
2. Set SnapStart to PublishedVersions
3. Point API Gateway to Alias in Lambda Integration




