Restarting AWS lambda function to clear cache

后端 未结 7 1684
你的背包
你的背包 2021-01-08 00:38

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

相关标签:
7条回答
  • 2021-01-08 00:46

    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.

    0 讨论(0)
  • 2021-01-08 00:50

    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"
    
    0 讨论(0)
  • 2021-01-08 01:02

    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)

    0 讨论(0)
  • 2021-01-08 01:03

    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.

    0 讨论(0)
  • 2021-01-08 01:03

    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

    0 讨论(0)
  • 2021-01-08 01:03

    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

    0 讨论(0)
提交回复
热议问题