

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

# CloudWatchEvent
<a name="sam-property-statemachine-statemachinecloudwatchevent"></a>

描述`CloudWatchEvent`事件來源類型的物件。

AWS Serverless Application Model (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) 資源。

**重要注意事項**： [EventBridgeRule](sam-property-statemachine-statemachineeventbridgerule.md)是要使用的慣用事件來源類型，而不是 `CloudWatchEvent`。 `EventBridgeRule` 和 `CloudWatchEvent`會使用相同的基礎服務、API CloudFormation 和資源。不過， AWS SAM 只會將新功能的支援新增至 `EventBridgeRule`。

## 語法
<a name="sam-property-statemachine-statemachinecloudwatchevent-syntax"></a>

若要在 AWS Serverless Application Model (AWS SAM) 範本中宣告此實體，請使用下列語法。

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

```
  [EventBusName](#sam-statemachine-statemachinecloudwatchevent-eventbusname): String
  [Input](#sam-statemachine-statemachinecloudwatchevent-input): String
  [InputPath](#sam-statemachine-statemachinecloudwatchevent-inputpath): String
  [Pattern](#sam-statemachine-statemachinecloudwatchevent-pattern): [EventPattern](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-eventpattern)
```

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

 `EventBusName`   <a name="sam-statemachine-statemachinecloudwatchevent-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-statemachine-statemachinecloudwatchevent-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-statemachine-statemachinecloudwatchevent-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)` 屬性。

 `Pattern`   <a name="sam-statemachine-statemachinecloudwatchevent-pattern"></a>
說明哪些事件會路由到指定目標。如需詳細資訊，請參閱《Amazon [ EventBridge 使用者指南》中的 EventBridge 中的事件和事件模式](https://docs.aws.amazon.com/eventbridge/latest/userguide/eventbridge-and-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)` 屬性。

## 範例
<a name="sam-property-statemachine-statemachinecloudwatchevent--examples"></a>

### CloudWatchEvent
<a name="sam-property-statemachine-statemachinecloudwatchevent--examples--cloudwatchevent"></a>

以下是`CloudWatchEvent`事件來源類型的範例。

#### YAML
<a name="sam-property-statemachine-statemachinecloudwatchevent--examples--cloudwatchevent--yaml"></a>

```
CWEvent:
  Type: CloudWatchEvent
  Properties:
    Input: '{"Key": "Value"}'
    Pattern:
      detail:
        state:
          - running
```