How to periodically call a Lambda function
source link: https://advancedweb.hu/how-to-periodically-call-a-lambda-function/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to periodically call a Lambda function
Configure a CloudWatch Event Rule to call a function according to a pattern
Timing events
Serverless architectures are event-driven, things start processing when there is something that triggers them. This makes it great to react to an API call, a new object in an S3 bucket, or a notification coming in a queue. But for scheduled tasks, such as triggering a daily backup or generating an aggregated seasonal report, Lambda needs a separate service to provide the events.
Fortunately, AWS offers such a service: the CloudWatch Event Rules. You can configure one to periodially call a Lambda function, among other potential event targets. It supports relative timing (run every 10 minutes) as well as absolute ones (run everyday at 3 a.m.). For the latter, it supports the CRON syntax, making it familiar to sysadmins.
This Event Rule is configured to run every minute (rate(1 minute)
) and it calls the function with the ARN on the third column:
Permissions
As a general pattern in AWS, services need permissions to call each other. This is usually done using a role that the caller uses, but CloudWatch Event Rule targets don’t support this pattern (even if there is a role argument, it does not work for Lambda).
For these cases, AWS supports a different mechanism: resource-based permissions.
Here, the Lambda function defines a permission that allows the events.amazonaws.com
service to call it:
By itself, it would open the door for all Event Rules, so use the AWS:SourceArn
condition to restrict it to this specific target:
{
"ArnLike": {
"AWS:SourceArn": "arn:aws:events:<region>:<account>:rule/<rulename>"
}
}
Testing
The Lambda is called every minute:
Recommend
-
93
chaoskube chaoskube periodically kills random pods in your Kubernetes cluster.
-
51
继续java8新亮点的源码之路,functional interface是一个跳不过的坎,它与lambda的结合使用非常普遍。 java.util.function 包对于每一个java工程师来说是必备技能,也是最基础的能力,一定要掌握。
-
35
README.md Laravel Heartbeat
-
47
readme.md
-
48
C++11 中增加了许多的新特性。 在本文中,我们来聊一下lambda表达式,闭包,std::function以及std::bind。 lambda 表达式 C++11中新增了lambda 表达式这一语言特性。lambda表达式可以让我们快速和...
-
31
SQL2Slack a cron deamon that executes the specified sql query and forward its result to slack () Features Tiny & Portable. Works with multiple sql engine. Cu...
-
8
Trace with data that is periodically advertisements I have a data file: ######## Test at 123.45 start ######## ######## File: abc.xy...
-
6
HIBA: Host Identity Based Authorization Pronounce: /hiːba/ What is HIBA HIBA is a system built on top of regular OpenSSH certificate-based authentication that allows to manage flexible authorization of principals on p...
-
7
How to Periodically Extract Webpage Performance Metrics from Browser APILive OpenSearch Online Training starting on October 12! See all...
-
3
Restart a docker container periodically with docker-compose · GitHub Instantly share cod...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK