

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

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

描述`EventBridgeRule`事件來源類型的物件，這會將您的無伺服器函數設定為 Amazon EventBridge 規則的目標。如需詳細資訊，請參閱《Amazon EventBridge 使用者指南》中的[什麼是 Amazon EventBridge？](https://docs.aws.amazon.com/eventbridge/latest/userguide/what-is-amazon-eventbridge.html)。

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`，這是必要的，以便 `EventBridgeRule`可以呼叫 Lambda。

## 語法
<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>
設定在目標呼叫失敗後 EventBridge 傳送事件的 Amazon Simple Queue Service (Amazon SQS) 佇列。例如，將事件傳送至不存在的 Lambda 函數時，或 EventBridge 沒有足夠的許可來叫用 Lambda 函數時，叫用可能會失敗。如需詳細資訊，請參閱《*Amazon EventBridge 使用者指南*》中的[事件重試政策和使用無效字母佇列](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>
此設定能讓您以特定事件資料為基礎，向目標提供自訂輸入。您可從事件擷取一或多組鍵/值對，然後使用該資料將自訂輸入傳送至目標。如需詳細資訊，請參閱《[Amazon EventBridge 使用者指南》中的 Amazon EventBridge 輸入轉換](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-transform-target-input.html)。 * EventBridge *   
*類型*：[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>
說明哪些事件會路由到指定目標。如需詳細資訊，請參閱《[Amazon EventBridge ](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-events.html) 使用者指南》中的 Amazon [EventBridge 事件和 EventBridge 事件模式](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-event-patterns.html)。 * EventBridge *  
*類型*：[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` 物件。如需詳細資訊，請參閱《*Amazon EventBridge 使用者指南*》中的[事件重試政策和使用無效字母佇列](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。  
*類型*：[Target](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 Simple Queue Service (Amazon SQS) 佇列的物件，其中 EventBridge 會在失敗的目標調用後傳送事件。例如，將事件傳送至不存在的 Lambda 函數時，呼叫可能會失敗，或沒有足夠的許可來叫用 Lambda 函數。如需詳細資訊，請參閱《*Amazon EventBridge 使用者指南*》中的[事件重試政策和使用無效字母佇列](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 Resource Name (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>
`Type` 指定 時 AWS SAM 建立的無效字母佇列自訂名稱。  
如果未設定 `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
```