

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# で EventBridge スケジューラを使用して時間ベースのイベントを管理する AWS SAM
<a name="using-eventbridge-scheduler"></a>

このトピックのコンテンツでは、Amazon EventBridge スケジューラの詳細、サポート AWS SAM オファー、スケジューライベントの作成方法、スケジューライベントの作成時に参照できる例について説明します。

## Amazon EventBridge スケジューラとは
<a name="using-eventbridge-scheduler-intro"></a>

EventBridge スケジューラを使用して、 AWS SAM テンプレートでイベントをスケジュールします。Amazon EventBridge スケジューラは、すべてのサービスで何千万ものイベントやタスクを作成、開始、管理できるスケジューリング AWS サービスです。このサービスは、時間関連のイベントに特に役立ちます。これは、イベントや定期的な時間ベースの呼び出しをスケジュールするために使用します。またこれは、1 回限りのイベントだけでなく、開始時刻と終了時刻を指定したレート式とChron 式もサポートしています。

Amazon EventBridge スケジューラの詳細については、「*EventBridge Scheduler User Guide*」の「[What is Amazon EventBridge Scheduler?](https://docs.aws.amazon.com/scheduler/latest/UserGuide/what-is-scheduler.html)」を参照してください。

**Topics**
+ [Amazon EventBridge スケジューラとは](#using-eventbridge-scheduler-intro)
+ [での EventBridge スケジューラのサポート AWS SAM](#using-eventbridge-scheduler-sam-support)
+ [での EventBridge スケジューライベントの作成 AWS SAM](#using-eventbridge-scheduler-sam-create)
+ [例](#using-eventbridge-scheduler-examples)
+ [詳細情報](#using-eventbridge-scheduler-learn)

## での EventBridge スケジューラのサポート AWS SAM
<a name="using-eventbridge-scheduler-sam-support"></a>

 AWS Serverless Application Model (AWS SAM) テンプレート仕様は、 AWS Lambda および の EventBridge スケジューラでイベントをスケジュールするために使用できるシンプルで短い構文を提供します AWS Step Functions。

## での EventBridge スケジューライベントの作成 AWS SAM
<a name="using-eventbridge-scheduler-sam-create"></a>

`ScheduleV2` プロパティを AWS SAM テンプレートのイベントタイプとして設定し、EventBridge スケジューライベントを定義します。このプロパティは、`AWS::Serverless::Function` および `AWS::Serverless::StateMachine` リソースタイプをサポートします。

```
MyFunction:
  Type: AWS::Serverless::Function
  Properties:
    Events:
      CWSchedule:
        Type: ScheduleV2
        Properties:
          ScheduleExpression: 'rate(1 minute)'
          Name: TestScheduleV2Function
          Description: Test schedule event
                    
MyStateMachine:
  Type: AWS::Serverless::StateMachine
  Properties:
    Events:
      CWSchedule:
        Type: ScheduleV2
        Properties:
          ScheduleExpression: 'rate(1 minute)'
          Name: TestScheduleV2StateMachine
          Description: Test schedule event
```

EventBridge スケジューラのイベントスケジューリングでは、未処理のイベントのデッドレターキュー (DLQ) もサポートされています。デッドレターキューの詳細については、「EventBridge スケジューラユーザーガイド」の「[Configuring a dead-letter queue for EventBridge Scheduler](https://docs.aws.amazon.com/scheduler/latest/UserGuide/configuring-schedule-dlq.html)」(EventBridge スケジューラのデッドレターキューの設定) を参照してください。

DLQ ARN を指定すると、 はスケジューラスケジュールのアクセス許可 AWS SAM を設定して DLQ にメッセージを送信します。DLQ ARN が指定されていない場合、 AWS SAM は DLQ リソースを作成します。

## 例
<a name="using-eventbridge-scheduler-examples"></a>

### で EventBridge スケジューライベントを定義する基本的な例 AWS SAM
<a name="using-eventbridge-scheduler-examples-example1"></a>

```
Transform: AWS::Serverless-2016-10-31
Resources:
  MyLambdaFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: python3.8
      InlineCode: |
        def handler(event, context):
            print(event)
            return {'body': 'Hello World!', 'statusCode': 200}
      MemorySize: 128
      Events:
        Schedule:
          Type: ScheduleV2
          Properties:
            ScheduleExpression: rate(1 minute)
            Input: '{"hello": "simple"}'
 
  MySFNFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: python3.8
      InlineCode: |
        def handler(event, context):
            print(event)
            return {'body': 'Hello World!', 'statusCode': 200}
      MemorySize: 128
 
  StateMachine:
    Type: AWS::Serverless::StateMachine
    Properties:
      Type: STANDARD
      Definition:
        StartAt: MyLambdaState
        States:
          MyLambdaState:
            Type: Task
            Resource: !GetAtt MySFNFunction.Arn
            End: true
      Policies:
        - LambdaInvokePolicy:
            FunctionName: !Ref MySFNFunction
      Events:
        Schedule:
          Type: ScheduleV2
          Properties:
            ScheduleExpression: rate(1 minute)
            Input: '{"hello": "simple"}'
```

## 詳細情報
<a name="using-eventbridge-scheduler-learn"></a>

`ScheduleV2` EventBridge スケジューラプロパティの定義の詳細については、以下を参照してください。
+ `AWS::Serverless::Function` 用の [ScheduleV2](sam-property-function-schedulev2.md)。
+ `AWS::Serverless::StateMachine` 用の [ScheduleV2](sam-property-statemachine-statemachineschedulev2.md)。