選取您的 Cookie 偏好設定

我們使用提供自身網站和服務所需的基本 Cookie 和類似工具。我們使用效能 Cookie 收集匿名統計資料,以便了解客戶如何使用我們的網站並進行改進。基本 Cookie 無法停用,但可以按一下「自訂」或「拒絕」以拒絕效能 Cookie。

如果您同意,AWS 與經核准的第三方也會使用 Cookie 提供實用的網站功能、記住您的偏好設定,並顯示相關內容,包括相關廣告。若要接受或拒絕所有非必要 Cookie,請按一下「接受」或「拒絕」。若要進行更詳細的選擇,請按一下「自訂」。

在 Step Functions 中使用 ResultPath 指定狀態輸出

焦點模式
在 Step Functions 中使用 ResultPath 指定狀態輸出 - AWS Step Functions

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

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

管理狀態和轉換資料

此頁面是指 JSONPath。Step Functions 最近新增了變數和 JSONata 來管理狀態和轉換資料。

了解如何使用變數傳遞資料,以及使用 JSONata 轉換資料

狀態的輸出可以是其輸入的複本、所產生的結果 (例如,從 Task 狀態之 Lambda 函數的輸出),或輸入和結果的結合。使用 ResultPath 以控制哪些組合會傳遞至狀態輸出。

以下狀態類型可以產生結果,並可包含 ResultPath:

使用 ResultPath 合併任務結果與任務輸入,或選取其中一個。您提供給 ResultPath 的路徑會控制哪些資訊會傳遞到輸出。

注意

ResultPath 僅限於使用參考路徑,這會限制範圍,因此路徑必須只識別 JSON 中的單一節點。請參閱 Amazon States 語言參考路徑中的 。

使用 ResultPath 將輸入取代為任務結果

如果您未指定 ResultPath,預設行為會與 相同"ResultPath": "$"。狀態會將整個狀態輸入取代為任務的結果。

# State Input { "comment": "This is a test", "details": "Default example", "who" : "Step Functions" } # Path "ResultPath": "$" # Task result "Hello, Step Functions!" # State Output "Hello, Step Functions!"
注意

ResultPath 是在傳遞至輸出之前,用於在輸入中包含來自結果的內容。但是,如果ResultPath未指定 ,則預設動作是取代整個輸入。

捨棄結果並保留原始輸入

如果您將 ResultPath設定為 null,狀態會將原始輸入傳遞給輸出。狀態的輸入承載會直接複製到輸出,而與任務結果無關。

# State Input { "comment": "This is a test", "details": "Default example", "who" : "Step Functions" } # Path "ResultPath": null # Task result "Hello, Step Functions!" # State Output { "comment": "This is a test", "details": "Default example", "who" : "Step Functions" }

使用 ResultPath 將結果與輸入一起包含

如果您為 ResultPath 指定路徑,狀態輸出將結合狀態輸入和任務結果:

# State Input { "comment": "This is a test", "details": "Default example", "who" : "Step Functions" } # Path "ResultPath": "$.taskresult" # Task result "Hello, Step Functions!" # State Output { "comment": "This is a test", "details": "Default example", "who" : "Step Functions", "taskresult" : "Hello, Step Functions!" }

您也可以在子節點的輸入中插入結果。將 ResultPath 設定為下列。

"ResultPath": "$.strings.lambdaresult"

根據下列輸入:

{ "comment": "An input comment.", "strings": { "string1": "foo", "string2": "bar", "string3": "baz" }, "who": "AWS Step Functions" }

任務結果會插入為輸入中strings節點的子項。

{ "comment": "An input comment.", "strings": { "string1": "foo", "string2": "bar", "string3": "baz", "lambdaresult": "Hello, Step Functions!" }, "who": "AWS Step Functions" }

狀態輸入現在會將原始輸入 JSON 做為子節點包含在結果中。

使用 ResultPath 以結果更新輸入中的節點

如果您指定 ResultPath 的現有節點,任務結果將取代該現有節點:

# State Input { "comment": "This is a test", "details": "Default example", "who" : "Step Functions" } # Path "ResultPath": "$.comment" # Task result "Hello, Step Functions!" # State Output { "comment": "Hello, Step Functions!", "details": "Default example", "who" : "Step Functions" }

使用 ResultPath 在 中包含錯誤和輸入 Catch

在某些情況下,您可能想要保留原始輸入的錯誤。在 Catch 中使用 ResultPath 以包含錯誤與原始輸入,而不是將其取代。

"Catch": [{ "ErrorEquals": ["States.ALL"], "Next": "NextTask", "ResultPath": "$.error" }]

如果之前的 Catch 陳述式截獲錯誤,它會在狀態輸入內的 error 節點包含結果。例如,透過以下輸入:

{"foo": "bar"}

在截獲錯誤時的狀態輸出如下。

{ "foo": "bar", "error": { "Error": "Error here" } }

如需錯誤處理的詳細資訊,請參閱以下內容:

隱私權網站條款Cookie 偏好設定
© 2025, Amazon Web Services, Inc.或其附屬公司。保留所有權利。