Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pause / resume a aws lambda function

For example I have lambda functions that consume messages from a KinesisStream. How do stop and resume the function so that I don't incur charges and I don't loose data in the stream.

I know that if the events keep failing, Kinesis will keep retrying and the cost can be very high.

I cannot delete the function because there is lots of automation around it through CloudFormation. Is there a way to stop and restart the function?

SOLUTION: http://alestic.com/2015/11/aws-lambda-kinesis-pause-resume

NOTE: Event sources for rules, log streaming, cannot be disable using the event source. You will not event get it in the list when calling the API using the SDK. For those you have to disable the Event Rule, or the Log Subscription.

like image 289
victor m Avatar asked Jun 22 '16 15:06

victor m


People also ask

Can you pause an AWS Lambda?

Can you stop an AWS Lambda Function? There is no way to stop a currently executing AWS Lambda function. But you can stop future invocations by setting concurrency to zero or disabling integrations.

How do I delay AWS Lambda?

One option is to use AWS Step Functions to trigger the AWS Lambda function after a given delay. Step Functions has a Wait state that can schedule or delay execution, so you can can implement a fairly simple Step Functions state machine that puts a delay in front of calling a Lambda function. No database required!


2 Answers

The updated Lambda console on AWS supports this in the UI now. Click on the Kinesis stream feeding your lambda function, toggle the "Enabled/Disabled" toggle at the bottom, and Save. This will essentially pause/resume your function.Screenshot - Toggling Kinesis input into Lambda

like image 69
Guy Harel Avatar answered Sep 28 '22 03:09

Guy Harel


Let's talk about Kinesis for a moment. When you pull records off the stream, Kinesis will not 'delete' those records until you 'checkpoint' the stream. You can read the same records over and over until you confirm with Kinesis that you don't need them anymore.

AWS Lambda does not checkpoint the stream until the function completes its execution without an error. (context.success())

If you deploy a Lambda function and it is broken in some way (exits with an exception/error), the Lambda function will not checkpoint the stream, and your records will stay in the stream for as long until retention period expires (24 hours, by default). The 'un-checkpointed' records can then be read in a subsequent Lambda execution.

During deployment, the same thing applies. Any currently executing Lambdas that are interrupted will not checkpoint the stream, and any currently executing Lambdas that complete successfully will checkpoint as you expect.

like image 24
devonlazarus Avatar answered Sep 28 '22 04:09

devonlazarus