I have a lambda function that will be called infrequently in Production, but it will be public-facing, so I want to avoid cold-starts. So I thought I could use provisioned concurrency to avoid this issue. My Cloudformation template looks as follows:
QuoteLinkServiceFunction:
Type: AWS::Serverless::Function
Properties:
# other lambda properties...
ProvisionedConcurrencyConfig:
ProvisionedConcurrentExecutions: 1
When I create this stack in my Test environment though (where I am the only user, and so there are no other calls happening concurrently), I still experience cold starts when returning to use this function after a few hours. Subsequent calls immediately after the first call run faster as the lambda is now warmed up.
The lambda console shows that the alias for this function has actually been set up with a provisioned concurrency of 1, and I have verified the ALB target group is pointed at the alias. So why am I still getting cold starts?
Are you sure these are really cold start latencies rather than problem with database connection? Have you think of using X-Ray for tracing? You could wrap the instruction you want to mesure inside a segment.
Here an example application.