EventBridgeによるスケジュール実行
cron式とrate式を使ったAmazon EventBridgeルールで、Lambda関数を定期的なスケジュールで実行する方法を学びます。
「EventBridgeによるスケジュール実行」はCoddyKit上の無料Serverless AWS Lambda Developmentレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはServerless AWS Lambda Development学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Serverless AWS Lambda Developmentコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Why Scheduled Functions?
Many tasks need to run on a timer: nightly reports, cache warming, cleanup jobs. EventBridge Scheduler triggers Lambda without any always-on server.
Rate vs Cron
EventBridge supports two schedule syntaxes:
- rate() for simple intervals.
- cron() for precise calendar times.
A Rate Expression
A rate expression runs every fixed interval. For example rate(5 minutes) fires every five minutes.
rate(1 hour)
rate(5 minutes)
rate(7 days)A Cron Expression
Cron gives calendar precision. AWS cron has six fields: minute, hour, day-of-month, month, day-of-week, year.
cron(0 8 * * ? *)
cron(0 0 1 * ? *)
cron(0/15 * * * ? *)The Scheduled Event Payload
The Lambda receives a JSON event describing the trigger. Scheduled events have a fixed shape with source aws.events.
{
"source": "aws.events",
"detail-type": "Scheduled Event",
"time": "2026-05-29T08:00:00Z"
}Handling a Scheduled Event
Your handler ignores most of the payload and simply does its periodic work.
def handler(event, context):
print('Running scheduled job at', event.get('time'))
# do cleanup, send report, etc.
return {'status': 'done'}Creating the Rule
You attach a schedule to a Lambda as an EventBridge rule with the Lambda as its target. The CLI shows the core idea.
aws events put-rule \
--name nightly-cleanup \
--schedule-expression 'cron(0 2 * * ? *)'Granting Permission
EventBridge must have permission to invoke your function. Add a resource policy allowing the events.amazonaws.com principal.
aws lambda add-permission \
--function-name cleanup \
--statement-id eb-invoke \
--action lambda:InvokeFunction \
--principal events.amazonaws.comTime Zones
Classic EventBridge rules run in UTC. The newer EventBridge Scheduler supports named time zones, which avoids manual offset math.
Idempotency Matters
A schedule may occasionally fire twice. Make scheduled jobs idempotent so a repeat run causes no harm.
Disabling a Schedule
You can disable a rule without deleting it, which is useful for pausing a job during maintenance windows.
aws events disable-rule --name nightly-cleanupQuick Check
Test your scheduling knowledge.
Recap
You can now schedule Lambda functions with EventBridge using rate and cron expressions, grant invoke permission, mind time zones, and keep jobs idempotent.
よくある質問
「EventBridgeによるスケジュール実行」レッスンは無料ですか?
はい。「EventBridgeによるスケジュール実行」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Serverless AWS Lambda Developmentコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Serverless AWS Lambda Developmentコースには全4レッスンが含まれています。
「EventBridgeによるスケジュール実行」で何を学びますか?
cron式とrate式を使ったAmazon EventBridgeルールで、Lambda関数を定期的なスケジュールで実行する方法を学びます。 ブラウザで直接実行するハンズオンコードでServerless AWS Lambda Developmentを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Serverless AWS Lambda Developmentを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのServerless AWS Lambda Developmentは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「EventBridgeによるスケジュール実行」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このServerless AWS Lambda Developmentレッスンでコードを書いて実行できますか?
はい。すべてのServerless AWS Lambda Developmentレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- イベント駆動アーキテクチャの基本
- API GatewayによるLambdaの呼び出し
- S3とSQSのイベントトリガー
- EventBridgeによるスケジュール実行