I have a AWS Lambda function that creates an object from a s3 call in cold start. I then hold the object in the cache while the function is warm to keep load times down. W
In addition to some of the valid answers above: I happened to run an experiment on the (average) AWS Lambda instance lifetime. I could not find instances that ran for much longer than (on average) two hours: https://xebia.com/blog/til-that-aws-lambda-terminates-instances-preemptively/.
TL;DR: AWS Lambda is preemptively terminating instances (even those handling traffic) after two hours, with a standard deviation of 30 minutes.
I made an Answer based on my comment and verification from @DejanVasic
aws lambda update-function-configuration --function-name "myLambda" --description "foo"
This will force the next invokation of the lambda to "cold start".
To verify:
@timestamp, @message | sort @timestamp desc | limit 1000 | filter @message like "cold_start:true"
If you are using the Lambda versioning system, another way to do this is by publishing a new version and using an alias to direct all traffic to it.
Here's an example:
Publish version:
aws lambda publish-version --function-name your-function-name-here
Update the alias pointing to the new version:
aws lambda update-alias --function-name your-function-name-here --name alias-name-here --function-version 123
(use the function version in the output message from the first command above)
Use the UpdateFunctionCode API endpoint to force a refresh of all containers. AWS SDKs wrap this up to make it easier for you to call the API using your preferred language.
The only way force lambda to discard existing containers is to redeploy the function with something different.
Check out my answer here: Force Discard AWS Lambda Container
Good luck, Moe
Easiest way I found was changing something in Basic Settings like timeout:
I've upped+1 by a second, saved, and the function got refreshed