Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restarting AWS lambda function to clear cache

Tags:

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. When files are changed in s3, I have a trigger to run the lambda, but not all the running instances of lambda restart and pull from s3.

Is there a way to bring down all instances of lambda forcing a full cold start?

Also, I don't want to use python.

like image 517
Marc Avatar asked Jun 14 '18 21:06

Marc


People also ask

How do I restart Lambda?

To restart the instance, Lambda will require an execution role with allowed permissions. Following permissions code will allow the Lambda function to log permissions into cloudwatch logs, and allows permissions to start and stop EC2 instances.

Does AWS Lambda have cache?

Cache data is stored in memory and not in a file within the Lambda execution environment. This means that no additional process is required to manage the lifecycle of the file. In-memory is also more secure, as data is not persisted to disk for subsequent function invocations.


2 Answers

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" 
like image 58
Baked Inhalf Avatar answered Oct 12 '22 17:10

Baked Inhalf


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.

like image 26
Renato Byrro Avatar answered Oct 12 '22 15:10

Renato Byrro