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

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

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

DescribeExecution 搭配 a AWS SDK 使用

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

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

.NET
AWS SDK for .NET
注意

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

/// <summary> /// Retrieve information about the specified Step Functions execution. /// </summary> /// <param name="executionArn">The Amazon Resource Name (ARN) of the /// Step Functions execution.</param> /// <returns>The API response returned by the API.</returns> public async Task<DescribeExecutionResponse> DescribeExecutionAsync(string executionArn) { var response = await _amazonStepFunctions.DescribeExecutionAsync(new DescribeExecutionRequest { ExecutionArn = executionArn }); return response; }
  • 如需 API 詳細資訊,請參閱 DescribeExecution AWS SDK for .NET 參考中的 API

Java
Java 2.x 的 SDK
注意

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

public static void describeExe(SfnClient sfnClient, String executionArn) { try { DescribeExecutionRequest executionRequest = DescribeExecutionRequest.builder() .executionArn(executionArn) .build(); String status = ""; boolean hasSucceeded = false; while (!hasSucceeded) { DescribeExecutionResponse response = sfnClient.describeExecution(executionRequest); status = response.statusAsString(); if (status.compareTo("RUNNING") == 0) { System.out.println("The state machine is still running, let's wait for it to finish."); Thread.sleep(2000); } else if (status.compareTo("SUCCEEDED") == 0) { System.out.println("The Step Function workflow has succeeded"); hasSucceeded = true; } else { System.out.println("The Status is neither running or succeeded"); } } System.out.println("The Status is " + status); } catch (SfnException | InterruptedException e) { System.err.println(e.getMessage()); System.exit(1); } }
  • 如需 API 詳細資訊,請參閱 DescribeExecution AWS SDK for Java 2.x 參考中的 API

Kotlin
Kotlin 的 SDK
注意

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

suspend fun describeExe(executionArnVal: String?) { val executionRequest = DescribeExecutionRequest { executionArn = executionArnVal } var status = "" var hasSucceeded = false while (!hasSucceeded) { SfnClient { region = "us-east-1" }.use { sfnClient -> val response = sfnClient.describeExecution(executionRequest) status = response.status.toString() if (status.compareTo("RUNNING") == 0) { println("The state machine is still running, let's wait for it to finish.") Thread.sleep(2000) } else if (status.compareTo("SUCCEEDED") == 0) { println("The Step Function workflow has succeeded") hasSucceeded = true } else { println("The Status is neither running or succeeded") } } } println("The Status is $status") }
  • 如需 API 詳細資訊,請參閱 DescribeExecution AWS for Kotlin SDK 參考中的 API

Python
Python 的 SDK (Boto3)
注意

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

def describe_run(self, run_arn): """ Get data about a state machine run, such as its current status or final output. :param run_arn: The ARN of the run to look up. :return: The retrieved run data. """ try: response = self.stepfunctions_client.describe_execution( executionArn=run_arn ) except ClientError as err: logger.error( "Couldn't describe run %s. Here's why: %s: %s", run_arn, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return response
  • 如需 API 詳細資訊,請參閱 DescribeExecution AWS SDK for Python (Boto3) Word 參考中的 API