先日、Amazon EventBridgeからスケジューリング機能を切り出した Amazon EventBridge Scheduler というサービスがリリースされました。
- Introducing Amazon EventBridge Scheduler | AWS Compute Blog
- [新機能] タイムゾーン指定でスケジュール起動できるAmazon EventBridge Schedulerがリリースされました | DevelopersIO
AWSサービスとのシームレスな連携や大幅に引き上げらたクオータ・スループットなどが特徴的です。
今回は、CloudFormation テンプレートを作成し、AWSリソースの観点からこれらサービスの違いを確認します。
EventBridge から StepFunctionsのステートマシンを呼び出すだけのリソースを作成します。
差分のまとめ
リソース視点でのこの2つの違いは以下の通りです。
サービス | Amazon EventBridge Scheduler | Amazon EventBridge Rule |
---|---|---|
ネームスペース | scheduler.amazonaws.com | events.amazonaws.com |
AWS CLI | $ aws scheduler command |
$ aws events command |
リソースタイプ | AWS::Scheduler::Schedule | AWS::Events::Rule |
スケジュールとターゲットの関係 | 1:1 | 1:多 |
EventBridge Scheduler の場合
※ CloudFormation テンプレート全体は本文最後を参照
EventBridge Schedulerでスケジューラーを作成する場合、 AWS::Scheduler::Schedule タイプを利用します。
Event Bridge Rule より詳細なスケジュール設定に対応しており、ウィンドウ指定のためのフィールド(FlexibleTimeWindow
) など新たなフィールドが追加されています。
Type: AWS::Scheduler::Schedule
Properties:
Description: Recurring StepFunctions Schedule
ScheduleExpression: rate(30 minutes)
FlexibleTimeWindow:
Mode: FLEXIBLE
MaximumWindowInMinutes: 60
State: ENABLED
スケジュール呼び出しする対象は Target
フィールドで定義します。
Target:
Arn:
Fn::GetAtt:
- HelloStateViaScheduler
- Arn
RoleArn:
Fn::GetAtt:
- EventScheduleRole
- Arn
細かいことですが、複数形の Targets
ではなく、単数形の Target
です。
EventBridge Scheduler では、スケジュールとターゲットの関係が 1:1 だからです。
スケジュールがターゲットを呼び出すためのロール(Execution Role)の信頼関係において、Principal
は scheduler.amazonaws.com
です。
EventBridge Rule 時代の events.amazonaws.com
ではありません。
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "scheduler.amazonaws.com"
}
}
]
}
CLI も $ aws scheduler cmd
形式で呼び出します。
EventBridge Rule の場合
※ CloudFormation テンプレート全体は本文最後を参照
EventBridge Ruleでスケジューラーを作成する場合、 AWS::Events::Rule タイプを利用します。
Type: AWS::Events::Rule
Properties:
Description: Recurring StepFunctions Schedule
ScheduleExpression: rate(30 minutes)
State: ENABLED
スケジュール呼び出しする対象は Targets
フィールドで定義します。
スケジュールとターゲットの関係は1対多のため、 Targets
と複数形です。
Targets:
- Arn:
Fn::GetAtt:
- HelloStateViaRule
- Arn
Id: HelloStateViaRule
RoleArn:
Fn::GetAtt:
- EventScheduleRole
- Arn
スケジュールがターゲットを呼び出すためのロール(Execution Role)の信頼関係において、Principal
は events.amazonaws.com
です。
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "events.amazonaws.com"
}
}
]
}
CLI も $ aws events cmd
形式で呼び出します。
差分のまとめ(詳細版)
Amazon EventBridge Scheduler と Amazon EventBridge rule の違いを、AWS 公式ブログにある表もマージする形で記載します。
サービス | Amazon EventBridge Scheduler | Amazon EventBridge rule |
---|---|---|
ネームスペース | scheduler.amazonaws.com | events.amazonaws.com |
AWS CLI | $ aws scheduler command |
$ aws events command |
リソースタイプ | AWS::Scheduler::Schedule | AWS::Events::Rule |
スケジュールとターゲットの関係 | 1:1 | 1:多 |
スケジュール数のクォータ | アカウント毎に 100 万 | 1 アカウントあたり、1 リージョンで 300 ルールの制限 |
イベント呼び出しのスループット | 1,000TPS 単位のスループットに対応可能 | 上限の300ルールを最短の1分スケジュールに設定して、最大 5 TPS |
ターゲット | AWS SDK ターゲットを使用した 270 以上のサービスと 6,000 以上の API アクション | 20 以上のターゲット |
時刻表現とタイムゾーン | at(), cron(), rate() すべてのタイムゾーンと DST(サマータイム) | cron(), rate() タイムゾーンは UTC のみ、DST のサポートなし |
1 回限りのスケジュール | Yes | No |
タイム ウィンドウ スケジュール | Yes | No |
イベントバスのサポート | イベントバス不要 | Default bus のみ |
ルールのクォータ消費 | 消費しない、100 万スケジュールのソフトリミット | 消費する、バスごとに 2,000 ルールから消費 |
まとめ
CloudFormation テンプレートを作成することで、EventBridge SchedulerとEventBridge Ruleの違いを学びました。
スケジュールとターゲットの関係がRule時代の1:多から1:1に変わったのには関心しました。
S3やEC2などのイベントがトリガーの場合、Fan Outできるように、1:多で実行するのが自然です。 一方で、スケジュールがトリガーの場合、タイムフレームを設けて1:1で実行するのが自然です。
CloudWatch Events が EventBridge にリブランディングされたときは、機能的には同じまま、製品名やUIが変わっただけでしたが、EventBridge Scheduler は EventBridge Rule とは独立したサービスです。
今後はイベントドリブンなものは EventBridge Rule、スケジュールドリブンなものは EventBridge Scheduler という明確な棲み分けのもと、それぞれが独自に進化すると思います。
それでは。
EventBridge SchedulerのCloudFormation
---
AWSTemplateFormatVersion: '2010-09-09'
Description: EventBridge Scheduler Demo
Resources:
EventSchedule:
Type: AWS::Scheduler::Schedule
Properties:
Description: Recurring StepFunctions Schedule
ScheduleExpression: rate(30 minutes)
FlexibleTimeWindow:
Mode: FLEXIBLE
MaximumWindowInMinutes: 60
State: ENABLED
Target:
Arn:
Fn::GetAtt:
- HelloStateViaScheduler
- Arn
RoleArn:
Fn::GetAtt:
- EventScheduleRole
- Arn
EventScheduleRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- scheduler.amazonaws.com
Action:
- sts:AssumeRole
Path: "/"
Policies:
- PolicyName: CallStepFunctions
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- states:StartExecution
Resource:
- "*"
HelloStateViaScheduler:
Type: AWS::StepFunctions::StateMachine
Properties:
RoleArn:
Fn::GetAtt:
- HelloStateViaSchedulerRole
- Arn
StateMachineType: STANDARD
DefinitionString: |-
{
"StartAt": "Pass",
"States": {
"Pass": {
"Type": "Pass",
"End": true
}
}
}
HelloStateViaSchedulerRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- states.amazonaws.com
Action:
- sts:AssumeRole
Path: "/"
EventBridge Rules のCloudFormation
---
AWSTemplateFormatVersion: '2010-09-09'
Description: EventBridge Rule Demo
Resources:
EventSchedule:
Type: AWS::Events::Rule
Properties:
Description: Recurring StepFunctions Schedule
ScheduleExpression: rate(30 minutes)
State: ENABLED
Targets:
- Arn:
Fn::GetAtt:
- HelloStateViaRule
- Arn
Id: HelloStateViaRule
RoleArn:
Fn::GetAtt:
- EventScheduleRole
- Arn
EventScheduleRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- events.amazonaws.com
Action:
- sts:AssumeRole
Path: "/"
Policies:
- PolicyName: CallStepFunctions
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- states:StartExecution
Resource:
- "*"
HelloStateViaRule:
Type: AWS::StepFunctions::StateMachine
Properties:
RoleArn:
Fn::GetAtt:
- HelloStateViaRuleRole
- Arn
StateMachineType: STANDARD
DefinitionString: |-
{
"StartAt": "Pass",
"States": {
"Pass": {
"Type": "Pass",
"End": true
}
}
}
HelloStateViaRuleRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- states.amazonaws.com
Action:
- sts:AssumeRole
Path: "/"