Server functions may experience performance issues due to Lambda cold starts. To mitigate this, the server function can be invoked periodically. Remember, Warming is optional and is only required if you want to keep the server function warm.
Please note, warming is currently only supported when the server function is deployed to a single region (Lambda).
Prewarm
Each time you deploy, a new version of the Lambda function will be generated. All warmed server function instances will be turned off. And there won't be any warm instances until the warmer function runs again at the next 5-minute interval.
To ensure the functions are prewarmed on deploy, create a CloudFormation Custom Resource (opens in a new tab) to invoke the warmer function on deployment. The custom resource should be configured as follows:
- Invoke the warmer function on resource
Create
andUpdate
. - Include a timestamp value in the resource property to ensure the custom resource runs on every deployment.
- Grant
lambda:InvokeFunction
permission to allow the custom resource to invoke the warmer function.
Cost
There are three components to the cost:
-
EventBridge scheduler: $0.00864
Requests cost — 8,640 invocations per month x $1/million = $0.00864
-
Warmer function: $0.145728288
Requests cost — 8,640 invocations per month x $0.2/million = $0.001728 Duration cost — 8,640 invocations per month x 1GB memory x 1s duration x $0.0000166667/GB-second = $0.144000288
-
Server function: $0.0161280288 per warmed instance
Requests cost — 8,640 invocations per month x $0.2/million = $0.001728 Duration cost — 8,640 invocations per month x 1GB memory x 100ms duration x $0.0000166667/GB-second = $0.0144000288
For example, keeping 50 instances of the server function warm will cost approximately $0.96 per month
$0.00864 + $0.145728288 + $0.0161280288 x 50 = $0.960769728
This cost estimate is based on the us-east-1
region pricing and does not consider any free tier benefits.