OnFailure - AWS Serverless Application Model

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

OnFailure

處理失敗事件的目標。

語法

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

YAML

Destination: String Type: String

屬性

Destination

目標資源的 Amazon Resource Name (ARN)。

類型:字串

必要:有條件

AWS CloudFormation 兼容性:此屬性類似於AWS::Lambda::EventInvokeConfig資源的OnFailure屬性。SAM 會將任何必要的權限新增至與此函數相關聯的自動產生 IAM 角色,以存取此屬性中參照的資源。

附加說明:如果類型為 Lambda/EventBridge,則需要目的地。

Type

目標中參照的資源類型。支援的類型有SQSSNSLambda、、和EventBridge

類型:字串

必要:否

AWS CloudFormation 兼容性:此屬性是唯一的, AWS SAM 並且沒有相 AWS CloudFormation 等的屬性。

其他注意事項:如果類型為 SQS/SNS,且內Destination容保留空白,則 SAM 會 auto 產生 SQS/SNS 資源。若要參照資源,請使<function-logical-id>.DestinationQueue用 SQS 或 <function-logical-id>.DestinationTopic SNS。如果類型是 Lambda/EventBridge,則Destination是必需的。

範例

EventInvoke SQS 和 Lambda 目的地的組態範例

在此範例中,沒有為 SQS OnSuccess 組態指定目的地,因此 SAM 會隱含地建立 SQS 佇列並新增任何必要的權限。此外,在此範例中,在範本檔案中宣告的 Lambda 資源目標也會在 OnFailure 組態中指定,因此 SAM 會將必要的權限新增至此 Lambda 函數,以呼叫目標 Lambda 函數。

YAML

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

EventInvoke SNS 目的地的組態範例

在此範例中,會為 OnSuccess 組態的範本檔案中宣告的 SNS 主題提供目的地。

YAML

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