

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# ScheduleV2
<a name="sam-property-statemachine-statemachineschedulev2"></a>

描述`ScheduleV2`事件源类型的对象，它将您的状态机设置为按计划触发的 Amazon S EventBridge cheduler 事件的目标。有关更多信息，请参阅[什么是 Amazon EventBridge 日程安排](https://docs.aws.amazon.com/scheduler/latest/UserGuide/what-is-scheduler.html)？ 在《*EventBridge 日程安排器用户指南》*中。

AWS Serverless Application Model (AWS SAM) 在设置此事件类型时生成[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html)资源。

## 语法
<a name="sam-property-statemachine-statemachineschedulev2-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-statemachine-statemachineschedulev2-syntax.yaml"></a>

```
DeadLetterConfig: DeadLetterConfig
[Description](#sam-statemachine-statemachineschedulev2-description): String
[EndDate](#sam-statemachine-statemachineschedulev2-enddate): String
[FlexibleTimeWindow](#sam-statemachine-statemachineschedulev2-flexibletimewindow): FlexibleTimeWindow
[GroupName](#sam-statemachine-statemachineschedulev2-groupname): String
[Input](#sam-statemachine-statemachineschedulev2-input): String
[KmsKeyArn](#sam-statemachine-statemachineschedulev2-kmskeyarn): String
[Name](#sam-statemachine-statemachineschedulev2-name): String
OmitName: Boolean
[PermissionsBoundary](#sam-statemachine-statemachineschedulev2-permissionsboundary): String
[RetryPolicy](#sam-statemachine-statemachineschedulev2-retrypolicy): RetryPolicy
[RoleArn](#sam-statemachine-statemachineschedulev2-rolearn): String
[ScheduleExpression](#sam-statemachine-statemachineschedulev2-scheduleexpression): String
[ScheduleExpressionTimezone](#sam-statemachine-statemachineschedulev2-scheduleexpressiontimezone): String
[StartDate](#sam-statemachine-statemachineschedulev2-startdate): String
[State](#sam-statemachine-statemachineschedulev2-state): String
```

## Properties
<a name="sam-property-statemachine-statemachineschedulev2-properties"></a>

 `DeadLetterConfig`   <a name="sam-statemachine-statemachineschedulev2-deadletterconfig"></a>
配置亚马逊简单队列服务 (Amazon SQS) Simple Queue Service 队列，目标调用失败后 EventBridge 在该队列中发送事件。例如，当向不存在的 Lambda 函数发送事件时，或者没有足够的权限调用 Lambda 函数 EventBridge 时，调用可能会失败。*有关更多信息，请参阅《日[ EventBridge 程安排器用户指南》中的为调度程序配置死信队列](https://docs.aws.amazon.com/scheduler/latest/UserGuide/configuring-schedule-dlq.html)。EventBridge *  
*类型*：[DeadLetterConfig](sam-property-statemachine-statemachinescheduledeadletterconfig.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::Scheduler::Schedule``Target`数据类型的`[DeadLetterConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-scheduler-schedule-target.html#cfn-scheduler-schedule-target-deadletterconfig)`属性。此属性的 AWS SAM 版本包括其他子属性， AWS SAM 以备您想要创建死信队列时使用。

 `Description`   <a name="sam-statemachine-statemachineschedulev2-description"></a>
计划的描述。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[Description](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-description)`属性。

 `EndDate`   <a name="sam-statemachine-statemachineschedulev2-enddate"></a>
以 UTC 为单位的日期，在此日期之前计划可以调用其目标。根据计划的重复表达式，调用可能会在您指定的 **EndDate** 或之前停止。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[EndDate](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-enddate)`属性。

 `FlexibleTimeWindow`   <a name="sam-statemachine-statemachineschedulev2-flexibletimewindow"></a>
允许配置可以调用计划的窗口。  
*类型*：[FlexibleTimeWindow](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-flexibletimewindow)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[FlexibleTimeWindow](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler.html#cfn-scheduler-schedule-flexibletimewindow)`属性。

 `GroupName`   <a name="sam-statemachine-statemachineschedulev2-groupname"></a>
将与此计划关联的计划组名称。如果未定义，则使用默认组。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[GroupName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-groupname)`属性。

 `Input`   <a name="sam-statemachine-statemachineschedulev2-input"></a>
传递到目标的有效 JSON 文本。如果使用此属性，则不会将事件文本本身的任何内容传递到目标。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule Target`资源的`[Input](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-scheduler-schedule-target.html#cfn-scheduler-schedule-target-input)`属性。

 `KmsKeyArn`   <a name="sam-statemachine-statemachineschedulev2-kmskeyarn"></a>
将用于加密客户数据的 KMS 密钥的 ARN。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[KmsKeyArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-kmskeyarn)`属性。

 `Name`   <a name="sam-statemachine-statemachineschedulev2-name"></a>
计划的名称。如果您未指定名称，则 AWS SAM 会生成格式为的名称，`StateMachine-Logical-IDEvent-Source-Name`并使用该 ID 作为计划名称。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[Name](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-name)`属性。

`OmitName`  <a name="sam-statemachine-statemachineschedulev2-omitname"></a>
默认情况下， AWS SAM 生成并使用格式为的计划名称*<State-machine-logical-ID><event-source-name>*。将此属性设置`true`为 CloudFormation 生成唯一的物理 ID，然后改用该物理 ID 作为计划名称。  
*类型*：布尔值  
*必需*：否  
*默认值*：`false`  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `PermissionsBoundary`   <a name="sam-statemachine-statemachineschedulev2-permissionsboundary"></a>
用于为角色设置权限边界的策略的 ARN。  
如果已定义，`PermissionsBoundary`则 AWS SAM 将对计划程序计划的目标 IAM 角色应用相同的边界。
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::IAM::Role`资源的`[PermissionsBoundary](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-role.html#cfn-iam-role-permissionsboundary)`属性。

 `RetryPolicy`   <a name="sam-statemachine-statemachineschedulev2-retrypolicy"></a>
包含有关重试策略设置的信息的 `RetryPolicy` 对象。  
*类型*：[RetryPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-scheduler-schedule-target.html#cfn-scheduler-schedule-target-retrypolicy)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule``Target`数据类型的`[RetryPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-scheduler-schedule-target.html#cfn-scheduler-schedule-target-retrypolicy)`属性。

 `RoleArn`   <a name="sam-statemachine-statemachineschedulev2-rolearn"></a>
调用计划时， EventBridge 计划程序将用于目标的 IAM 角色的 ARN。  
*类型*：[RoleArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-scheduler-schedule-target.html#cfn-scheduler-schedule-target-rolearn)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule``Target`数据类型的`[RoleArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-scheduler-schedule-target.html#cfn-scheduler-schedule-target-rolearn)`属性。

 `ScheduleExpression`   <a name="sam-statemachine-statemachineschedulev2-scheduleexpression"></a>
决定运行计划的时间和频率的计划表达式。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[ScheduleExpression](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-scheduleexpression)`属性。

 `ScheduleExpressionTimezone`   <a name="sam-statemachine-statemachineschedulev2-scheduleexpressiontimezone"></a>
评估计划表达式的时区。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[ScheduleExpressionTimezone](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-scheduleexpressiontimezone)`属性。

 `StartDate`   <a name="sam-statemachine-statemachineschedulev2-startdate"></a>
以 UTC 为单位的日期，在此日期之后计划可以调用目标。根据计划的重复表达式，调用可能会在您指定的 **StartDate** 或之后发生。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[StartDate](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-startdate)`属性。

 `State`   <a name="sam-statemachine-statemachineschedulev2-state"></a>
计划的状态。  
*接受的值：*`DISABLED | ENABLED`  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[State](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-state)`属性。

## 示例
<a name="sam-property-statemachine-statemachineschedulev2--examples"></a>

### 定义 ScheduleV2 资源的基本示例
<a name="sam-property-statemachine-statemachineschedulev2--examples--example1"></a>

```
StateMachine:
  Type: AWS::Serverless::StateMachine
  Properties:
    Name: MyStateMachine
    Events:
      ScheduleEvent:
        Type: ScheduleV2
        Properties:
          ScheduleExpression: "rate(1 minute)"
      ComplexScheduleEvent:
        Type: ScheduleV2
        Properties:
          ScheduleExpression: rate(1 minute)
          FlexibleTimeWindow:
            Mode: FLEXIBLE
            MaximumWindowInMinutes: 5
          StartDate: '2022-12-28T12:00:00.000Z'
          EndDate: '2023-01-28T12:00:00.000Z'
          ScheduleExpressionTimezone: UTC
          RetryPolicy:
            MaximumRetryAttempts: 5
            MaximumEventAgeInSeconds: 300
          DeadLetterConfig:
            Type: SQS
    DefinitionUri:
      Bucket: sam-sam-s3-demo-bucket
      Key: my-state-machine.asl.json
      Version: 3
    Policies:
      - LambdaInvokePolicy:
          FunctionName: !Ref MyFunction
```