SendTaskSuccess 搭配 使用 AWS SDK - AWS SDK 程式碼範例

文件範例儲存庫中有更多 AWS SDK可用的AWS SDK範例 GitHub 。

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

SendTaskSuccess 搭配 使用 AWS SDK

下列程式碼範例示範如何使用 SendTaskSuccess

動作範例是大型程式的程式碼摘錄,必須在內容中執行。您可以在下列程式碼範例的內容中看到此動作:

.NET
AWS SDK for .NET
注意

還有更多功能 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

/// <summary> /// Indicate that the Step Functions task, indicated by the /// task token, has completed successfully. /// </summary> /// <param name="taskToken">Identifies the task.</param> /// <param name="taskResponse">The response received from executing the task.</param> /// <returns>A Boolean value indicating the success of the action.</returns> public async Task<bool> SendTaskSuccessAsync(string taskToken, string taskResponse) { var response = await _amazonStepFunctions.SendTaskSuccessAsync(new SendTaskSuccessRequest { TaskToken = taskToken, Output = taskResponse }); return response.HttpStatusCode == System.Net.HttpStatusCode.OK; }
  • 如需API詳細資訊,請參閱 AWS SDK for .NET API 參考SendTaskSuccess中的 。

Java
SDK 適用於 Java 2.x
注意

還有更多功能 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

public static void sendTaskSuccess(SfnClient sfnClient, String token, String json) { try { SendTaskSuccessRequest successRequest = SendTaskSuccessRequest.builder() .taskToken(token) .output(json) .build(); sfnClient.sendTaskSuccess(successRequest); } catch (SfnException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • 如需API詳細資訊,請參閱 AWS SDK for Java 2.x API 參考SendTaskSuccess中的 。

Kotlin
SDK 適用於 Kotlin
注意

還有更多功能 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

suspend fun sendTaskSuccess( token: String?, json: String?, ) { val successRequest = SendTaskSuccessRequest { taskToken = token output = json } SfnClient { region = "us-east-1" }.use { sfnClient -> sfnClient.sendTaskSuccess(successRequest) } }
  • 如需API詳細資訊,請參閱 SendTaskSuccess 中的 AWS SDK Kotlin API參考

Python
SDK for Python (Boto3)
注意

還有更多功能 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

class Activity: """Encapsulates Step Function activity actions.""" def __init__(self, stepfunctions_client): """ :param stepfunctions_client: A Boto3 Step Functions client. """ self.stepfunctions_client = stepfunctions_client def send_task_success(self, task_token, task_response): """ Sends a success response to a waiting activity step. A state machine with an activity step waits for the activity to get task data and then respond with either success or failure before it resumes processing. :param task_token: The token associated with the task. This is included in the response to the get_activity_task action and must be sent without modification. :param task_response: The response data from the activity. This data is received and processed by the state machine. """ try: self.stepfunctions_client.send_task_success( taskToken=task_token, output=task_response ) except ClientError as err: logger.error( "Couldn't send task success. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise
  • 如需API詳細資訊,請參閱 SendTaskSuccess 中的 AWS SDK for Python (Boto3) API參考