

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

# EventBridgeRule
<a name="sam-property-function-eventbridgerule"></a>

描述`EventBridgeRule`事件源类型的对象，它将您的无服务器函数设置为 Amazon EventBridge 规则的目标。有关更多信息，请参阅[什么是亚马逊 EventBridge？](https://docs.aws.amazon.com/eventbridge/latest/userguide/what-is-amazon-eventbridge.html) 在《*亚马逊 EventBridge 用户指南》*中。

AWS SAM 设置此事件类型时会生成[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html)资源。 AWS SAM 还会创建`AWS::Lambda::Permission`资源，该资源是调用 Lambda 所`EventBridgeRule`必需的。

## 语法
<a name="sam-property-function-eventbridgerule-syntax"></a>

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

### YAML
<a name="sam-property-function-eventbridgerule-syntax.yaml"></a>

```
  [DeadLetterConfig](#sam-function-eventbridgerule-deadletterconfig): DeadLetterConfig
  [EventBusName](#sam-function-eventbridgerule-eventbusname): String
  [Input](#sam-function-eventbridgerule-input): String
  [InputPath](#sam-function-eventbridgerule-inputpath): String
  InputTransformer: [InputTransformer](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-inputtransformer.html)
  [Pattern](#sam-function-eventbridgerule-pattern): [EventPattern](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-eventpattern)
  [RetryPolicy](#sam-function-eventbridgerule-retrypolicy): [RetryPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-retrypolicy)
  RuleName: String 
  State: String
  [Target](#sam-function-eventbridgerule-target): Target
```

## Properties
<a name="sam-property-function-eventbridgerule-properties"></a>

 `DeadLetterConfig`   <a name="sam-function-eventbridgerule-deadletterconfig"></a>
配置亚马逊简单队列服务 (Amazon SQS) Simple Queue Service 队列，目标调用失败后 EventBridge 在该队列中发送事件。例如，当向不存在的 Lambda 函数发送事件时，或者没有足够的权限调用 Lambda 函数 EventBridge 时，调用可能会失败。有关更多信息，请参阅 A *ma EventBridge * zon 用户指南中的[事件重试策略和使用死信队列](https://docs.aws.amazon.com/eventbridge/latest/userguide/rule-dlq.html)。  
[AWS::Serverless::Function](sam-resource-function.md) 资源类型具有类似的数据类型 `DeadLetterQueue`，用于处理成功调用目标 Lambda 函数后发生的故障。这些类型的故障示例包括 Lambda 节流或 Lambda 目标函数返回的错误。有关函数 `DeadLetterQueue` 属性的更多信息，请参阅*《AWS Lambda 开发人员指南》*中的[死信队列](https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html#invocation-dlq)。
*类型*：[DeadLetterConfig](sam-property-function-deadletterconfig.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::Events::Rule``Target`数据类型的`[DeadLetterConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-deadletterconfig)`属性。此属性的 AWS SAM 版本包括其他子属性， AWS SAM 以备您想要创建死信队列时使用。

 `EventBusName`   <a name="sam-function-eventbridgerule-eventbusname"></a>
要与该规则关联的事件总线。如果省略此属性，则 AWS SAM 使用默认的事件总线。  
*类型*：字符串  
*必需*：否  
*默认*：默认事件总线  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule`资源的`[EventBusName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-eventbusname)`属性。

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

 `InputPath`   <a name="sam-function-eventbridgerule-inputpath"></a>
当您不希望将整个匹配事件传递给目标时，请使用 `InputPath` 属性描述要传递事件的哪一部分。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule Target`资源的`[InputPath](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-inputpath)`属性。

 `InputTransformer`   <a name="sam-function-eventbridgerule-inputtransformer"></a>
使您可以根据特定事件数据向目标提供自定义输入的设置。您可以从事件中提取一个或多个键值对，然后使用该数据将自定义输入发送到目标。有关更多信息，请参阅[亚马逊* EventBridge 用户指南中的亚马逊 EventBridge *输入转换](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-transform-target-input.html)。  
*类型*：[InputTransformer](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-inputtransformer)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule``Target`数据类型的`[InputTransformer](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-inputtransformer.html)`属性。

 `Pattern`   <a name="sam-function-eventbridgerule-pattern"></a>
描述哪些事件路由到指定目标。有关更多信息，请参阅[亚马逊* EventBridge 用户指南中的亚马逊 EventBridgeEventBridge *事件](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-events.html)[和事件模式](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-event-patterns.html)。  
*类型*：[EventPattern](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-eventpattern)  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule`资源的`[EventPattern](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-eventpattern)`属性。

 `RetryPolicy`   <a name="sam-function-eventbridgerule-retrypolicy"></a>
包含有关重试策略设置的信息的 `RetryPolicy` 对象。有关更多信息，请参阅 A *ma EventBridge * zon 用户指南中的[事件重试策略和使用死信队列](https://docs.aws.amazon.com/eventbridge/latest/userguide/rule-dlq.html)。  
*类型*：[RetryPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-retrypolicy)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule``Target`数据类型的`[RetryPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-retrypolicy)`属性。

 `RuleName`   <a name="sam-function-eventbridgerule-rulename"></a>
 规则的名称。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule`资源的`[Name](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-name)`属性。

 `State`   <a name="sam-function-eventbridgerule-state"></a>
规则的状态。  
*接受的值*：`DISABLED` \$1 `ENABLED` \$1 `ENABLED_WITH_ALL_CLOUDTRAIL_MANAGEMENT_EVENTS`  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule`资源的`[State](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-state) `属性。

 `Target`   <a name="sam-function-eventbridgerule-target"></a>
触发规则时 EventBridge 调用的 AWS 资源。您可以使用此属性来指定目标的逻辑 ID。如果未指定此属性，则 AWS SAM 生成目标的逻辑 ID。  
*类型*：[目标](sam-property-function-target.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::Events::Rule`资源的`[Targets](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-targets)`属性。 `Amazon EC2 RebootInstances API call`是目标属性的示例。此属性的 AWS SAM 版本仅允许您指定单个目标的逻辑 ID。

## 示例
<a name="sam-property-function-eventbridgerule--examples"></a>

### EventBridgeRule
<a name="sam-property-function-eventbridgerule--examples--eventbridgerule"></a>

以下是 `EventBridgeRule` 事件源类型的示例。

#### YAML
<a name="sam-property-function-eventbridgerule--examples--eventbridgerule--yaml"></a>

```
EBRule:
  Type: EventBridgeRule
  Properties:
    Input: '{"Key": "Value"}'
    Pattern:
      detail:
        state:
          - terminated
    RetryPolicy:
      MaximumRetryAttempts: 5
      MaximumEventAgeInSeconds: 900
    DeadLetterConfig:
      Type: SQS
      QueueLogicalId: EBRuleDLQ
    Target:
      Id: MyTarget
```

# DeadLetterConfig
<a name="sam-property-function-deadletterconfig"></a>

该对象用于指定亚马逊简单队列服务 (Amazon SQS) Simple Queue Service 队列，目标调用失败后 EventBridge 在该队列中发送事件。例如，在向不存在的 Lambda 函数发送事件或调用 Lambda 函数的权限不足时，调用可能会失败。有关更多信息，请参阅 A *ma EventBridge * zon 用户指南中的[事件重试策略和使用死信队列](https://docs.aws.amazon.com/eventbridge/latest/userguide/rule-dlq.html)。

**注意**  
[AWS::Serverless::Function](sam-resource-function.md) 资源类型具有类似的数据类型 `DeadLetterQueue`，用于处理成功调用目标 Lambda 函数后发生的故障。此类故障的示例包括 Lambda 节流或 Lambda 目标函数返回的错误。有关函数 `DeadLetterQueue` 属性的更多信息，请参阅*《AWS Lambda 开发人员指南》*中的[死信队列](https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html#invocation-dlq)。

## 语法
<a name="sam-property-function-deadletterconfig-syntax"></a>

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

### YAML
<a name="sam-property-function-deadletterconfig-syntax.yaml"></a>

```
  [Arn](#sam-function-deadletterconfig-arn): String
  [QueueLogicalId](#sam-function-deadletterconfig-queuelogicalid): String
  [Type](#sam-function-deadletterconfig-type): String
```

## Properties
<a name="sam-property-function-deadletterconfig-properties"></a>

 `Arn`   <a name="sam-function-deadletterconfig-arn"></a>
指定作为死信队列目标的 Amazon SQS 队列的 Amazon 资源名称（ARN）。  
指定 `Type` 属性或 `Arn` 属性，但不能同时指定两者。
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule``DeadLetterConfig`数据类型的`[Arn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-deadletterconfig.html#cfn-events-rule-deadletterconfig-arn)`属性。

 `QueueLogicalId`   <a name="sam-function-deadletterconfig-queuelogicalid"></a>
指定了 AWS SAM 创建的死信队列的自定义名称。`Type`  
如果未设置 `Type` 属性，则将忽略该属性。
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Type`   <a name="sam-function-deadletterconfig-type"></a>
队列的类型。设置此属性后， AWS SAM 会自动创建死信队列并附加必要的[基于资源的策略](https://docs.aws.amazon.com/eventbridge/latest/userguide/rule-dlq.html#dlq-perms)，以授予规则资源向队列发送事件的权限。  
指定 `Type` 属性或 `Arn` 属性，但不能同时指定两者。
*有效值*：`SQS`  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-function-deadletterconfig--examples"></a>

### DeadLetterConfig
<a name="sam-property-function-deadletterconfig--examples--deadletterconfig"></a>

DeadLetterConfig

#### YAML
<a name="sam-property-function-deadletterconfig--examples--deadletterconfig--yaml"></a>

```
DeadLetterConfig:
  Type: SQS
  QueueLogicalId: MyDLQ
```

# Target
<a name="sam-property-function-target"></a>

配置触发规则时 EventBridge 调用的 AWS 资源。

## 语法
<a name="sam-property-function-target-syntax"></a>

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

### YAML
<a name="sam-property-function-target-syntax.yaml"></a>

```
  [Id](#sam-function-target-id): String
```

## Properties
<a name="sam-property-function-target-properties"></a>

 `Id`   <a name="sam-function-target-id"></a>
目标的逻辑 ID。  
`Id` 的值可以包含字母数字字符、句点 (`.`)、连字符 (`-`) 和下划线 (`_`)。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule``Target`数据类型的`[Id](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-id)`属性。

## 示例
<a name="sam-property-function-target--examples"></a>

### Target
<a name="sam-property-function-target--examples--target"></a>

#### YAML
<a name="sam-property-function-target--examples--target--yaml"></a>

```
EBRule:
  Type: EventBridgeRule
  Properties:
    Target:
      Id: MyTarget
```