

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

# OnFailure
<a name="sam-property-function-onfailure"></a>

處理失敗事件的目標。

## 語法
<a name="sam-property-function-onfailure-syntax"></a>

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

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

```
  [Destination](#sam-function-onfailure-destination): String
  [Type](#sam-function-onfailure-type): String
```

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

 `Destination`   <a name="sam-function-onfailure-destination"></a>
目標資源的 Amazon Resource Name (ARN)。  
*類型：*字串  
*必要*：有條件  
*CloudFormation 相容性*：此屬性類似於 `AWS::Lambda::EventInvokeConfig` 資源的 `[OnFailure](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventinvokeconfig-onfailure.html)` 屬性。SAM 會將任何必要的許可新增至與此函數相關聯的自動產生 IAM 角色，以存取此屬性中參考的資源。  
*其他備註*：如果類型為 Lambda/EventBridge，則需要目的地。

 `Type`   <a name="sam-function-onfailure-type"></a>
目的地中參考的資源類型。支援的類型為 `SQS`、`SNS`、`Lambda`、 `S3`和 `EventBridge`。  
*類型：*字串  
*必要*：否  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等屬性。  
*其他備註*：如果類型為 SQS/SNS 且`Destination`屬性為空白，則 SAM 會自動產生 SQS/SNS 資源。若要參考 資源，請`<function-logical-id>.DestinationQueue`針對 SQS 使用 ，或`<function-logical-id>.DestinationTopic`針對 SNS 使用 。如果類型為 Lambda/EventBridge，`Destination`則為必要項目。

## 範例
<a name="sam-property-function-onfailure--examples"></a>

### 使用 SQS 和 Lambda 目的地的 EventInvoke 組態範例
<a name="sam-property-function-onfailure--examples--eventinvoke-configuration-example-with-sqs-and-lambda-destinations"></a>

在此範例中，SQS OnSuccess 組態不會指定目的地，因此 SAM 會隱含地建立 SQS 佇列並新增任何必要的許可。此外，在此範例中，範本檔案中宣告的 Lambda 資源目的地是在 OnFailure 組態中指定，因此 SAM 會將必要的許可新增至此 Lambda 函數，以呼叫目的地 Lambda 函數。

#### YAML
<a name="sam-property-function-onfailure--examples--eventinvoke-configuration-example-with-sqs-and-lambda-destinations--yaml"></a>

```
EventInvokeConfig:
  DestinationConfig:
    OnSuccess:
      Type: SQS
    OnFailure:
      Type: Lambda
      Destination: !GetAtt DestinationLambda.Arn  # Arn of a Lambda function declared in the template file.
```

### 使用 SNS 目的地的 EventInvoke 組態範例
<a name="sam-property-function-onfailure--examples--eventinvoke-configuration-example-with-sns-destination"></a>

在此範例中，會為 OnSuccess 組態的範本檔案中宣告的 SNS 主題指定目的地。

#### YAML
<a name="sam-property-function-onfailure--examples--eventinvoke-configuration-example-with-sns-destination--yaml"></a>

```
EventInvokeConfig:
  DestinationConfig:
    OnSuccess:
      Type: SNS
      Destination:
        Ref: DestinationSNS       # Arn of an SNS topic declared in the tempate file
```