Call AWS Lambda regularly every 1 minute

How can I run AWMS Lambda regularly every minute ? The current functionality allows you to configure Lambdas with a 5-minute trigger , but I'm looking for a much shorter time interval. I was thinking about starting Lambda forever, but it seems like this is impossible to do since Maximum execution duration per request 300 seconds

+5
source share
3 answers

[Removed previous answer and update] AWS Lambda now provides an instantaneous CloudWatch Events frequency - schedule as a trigger option. enter image description here

+3
source

A session was held at AWS Reinvent in 2015 to address this exact topic, you can watch it here on youtube: https://www.youtube.com/watch?v=FhJxTIq81AU shows how to use lambda and cloudwatch to get this 1 minute frequency without external dependencies.

Do you need to run the AWS Lambda function on schedule, without an event to trigger a call? This session shows how to use Amazon CloudWatch and CloudWatch, Amazon SNS and Lambda signals so that Lambda launches every minute - no external services required! From here, other Lambda jobs can be scheduled in a crontab-like format that provides the minimum scheduled resolution for your Lambda. During the session, we create this functionality from scratch using the lambda function, CloudWatch metrics and alarms, sample triggers and tasks.

I suspect that at some point AWS will allow a 1-minute interval without using this method, but that may delay you on average.

+3
source

Using the boto module, you can force the lambda function to invoke the invoke statement by calling itself. The following will run every ~ 60 seconds. Of course, make sure you assign the appropriate role with permissions. Also pay attention to your limitations.

 import boto3,time def lambda_handler(event, context): #do something time.sleep(60) client = boto3.client('lambda') response = client.invoke(FunctionName='YOUR-FUNCTION-NAME') 
0
source

Source: https://habr.com/ru/post/1242545/


All Articles