Reputation: 41
I'm trying to make the switch from AWS Lambda warmup (calling the function every 5 minutes) to provisioned concurrency as I was told it's a better way to avoid cold starts. Nevertheless, when using provisioned concurrency, my script is going through all packages imports, which makes the latency quite important. For the same lambda function in two different environments, one using warmup and one using provisioned concurrency, the one using warmup executes in less than 1s when the other one takes almost a minute.
All of my imports are of course outside of the function handler, and the provisioned concurrency seems to be correctly enabled for my Lambda. To enable it I just added this line in my .yml file:
provisionedConcurrency: 3
Am I missing something or provisioned concurrency is not handling libraries imports when creating containers?
Upvotes: 4
Views: 1755
Reputation: 104
How is the lambda invoked?
provisioned concurrency is set on lambda alias/version (can't be set on $LATEST). In serverless framework, provisionedConcurrency: 3
will configure provisioned concurrency on lambda alias "provisioned" (this is the default and can't be cahnged), with 3 instances.
So whoever calling your lambda (api gateway / other lambda / sqs / sns / etc) need to invoke the alias instance. If you are not invoking the alias version, you are just invoking $LATEST which is not provisioned...
Invoke the alias by attaching it to end of function arn: rn:aws:lambda:us-west-2:123456789012:function:my-function:provisioned
or by adding qualifier
parameter in relevant field
Upvotes: 5