每 1 分钟定期调用 AWS Lambda
Invoke AWS Lambda(s) regularly every 1 minute
如何定期调用 AWS Lambda,特别是每 1 分钟?
当前功能允许使用 5 minute trigger 设置 Lambda,但我正在寻找更小的时间间隔。
我一直想到 运行 Lambda,但看起来这是不可能的,因为
Maximum execution duration per request 300 seconds
2015 年 AWS Reinvent 上有一个 session 涵盖了这个确切的主题,您可以在 youtube 上观看:https://www.youtube.com/watch?v=FhJxTIq81AU 展示了如何使用 lambda 和 cloudwatch 获得 1 分钟的频率没有外部依赖性。
Do you need to run an AWS Lambda function on a schedule, without an
event to trigger the invocation? This session shows how to use an
Amazon CloudWatch metric and CloudWatch alarms, Amazon SNS, and Lambda
so that Lambda triggers itself every minute—no external services
required! From here, other Lambda jobs can be scheduled in
crontab-like format, giving minute-level resolution to your Lambda
scheduled tasks. During the session, we build this functionality up
from scratch with a Lambda function, CloudWatch metric and alarms,
sample triggers, and tasks.
我怀疑在某些时候 AWS 会在不使用此方法的情况下允许 1 分钟的间隔,但这可能会使您在这段时间内停滞不前。
[删除之前的回答和更新]
现在,AWS Lambda 提供每分钟频率的 CloudWatch Events - Schedule 作为触发选项。
使用 boto 模块,您可以拥有一个 lambda 函数 运行 一个 invoke 语句,调用自身。以下将每 ~60 秒 运行。当然,请确保您分配了具有权限的适当角色。另外,请注意您的限制。
import boto3,time
def lambda_handler(event, context):
#do something
time.sleep(60)
client = boto3.client('lambda')
response = client.invoke(FunctionName='YOUR-FUNCTION-NAME')
再添加一个approach/solution:
我们可以使用 AWS EventBridge 在特定时间间隔触发 Lambda。
文档 -> https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-run-lambda-schedule.html
YouTube -> https://www.youtube.com/watch?v=uUhEKtLrGvo
如何定期调用 AWS Lambda,特别是每 1 分钟?
当前功能允许使用 5 minute trigger 设置 Lambda,但我正在寻找更小的时间间隔。
我一直想到 运行 Lambda,但看起来这是不可能的,因为
Maximum execution duration per request 300 seconds
2015 年 AWS Reinvent 上有一个 session 涵盖了这个确切的主题,您可以在 youtube 上观看:https://www.youtube.com/watch?v=FhJxTIq81AU 展示了如何使用 lambda 和 cloudwatch 获得 1 分钟的频率没有外部依赖性。
Do you need to run an AWS Lambda function on a schedule, without an event to trigger the invocation? This session shows how to use an Amazon CloudWatch metric and CloudWatch alarms, Amazon SNS, and Lambda so that Lambda triggers itself every minute—no external services required! From here, other Lambda jobs can be scheduled in crontab-like format, giving minute-level resolution to your Lambda scheduled tasks. During the session, we build this functionality up from scratch with a Lambda function, CloudWatch metric and alarms, sample triggers, and tasks.
我怀疑在某些时候 AWS 会在不使用此方法的情况下允许 1 分钟的间隔,但这可能会使您在这段时间内停滞不前。
[删除之前的回答和更新]
现在,AWS Lambda 提供每分钟频率的 CloudWatch Events - Schedule 作为触发选项。
使用 boto 模块,您可以拥有一个 lambda 函数 运行 一个 invoke 语句,调用自身。以下将每 ~60 秒 运行。当然,请确保您分配了具有权限的适当角色。另外,请注意您的限制。
import boto3,time
def lambda_handler(event, context):
#do something
time.sleep(60)
client = boto3.client('lambda')
response = client.invoke(FunctionName='YOUR-FUNCTION-NAME')
再添加一个approach/solution:
我们可以使用 AWS EventBridge 在特定时间间隔触发 Lambda。
文档 -> https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-run-lambda-schedule.html
YouTube -> https://www.youtube.com/watch?v=uUhEKtLrGvo