AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
GetActivityTask
搭配使用 AWS SDK
以下代码示例演示如何使用 GetActivityTask
。
操作示例是大型程序的代码摘录,必须在上下文中运行。在以下代码示例中,您可以查看此操作的上下文:
- .NET
-
- AWS SDK for .NET
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 /// <summary> /// Retrieve a task with the specified Step Functions activity /// with the specified Amazon Resource Name (ARN). /// </summary> /// <param name="activityArn">The Amazon Resource Name (ARN) of /// the Step Functions activity.</param> /// <param name="workerName">The name of the Step Functions worker.</param> /// <returns>The response from the Step Functions activity.</returns> public async Task<GetActivityTaskResponse> GetActivityTaskAsync(string activityArn, string workerName) { var response = await _amazonStepFunctions.GetActivityTaskAsync(new GetActivityTaskRequest { ActivityArn = activityArn, WorkerName = workerName }); return response; }
-
有关API详细信息,请参阅 “AWS SDK for .NET API参考 GetActivityTask” 中的。
-
- Java
-
- SDK适用于 Java 2.x
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 public static List<String> getActivityTask(SfnClient sfnClient, String actArn) { List<String> myList = new ArrayList<>(); GetActivityTaskRequest getActivityTaskRequest = GetActivityTaskRequest.builder() .activityArn(actArn) .build(); GetActivityTaskResponse response = sfnClient.getActivityTask(getActivityTaskRequest); myList.add(response.taskToken()); myList.add(response.input()); return myList; } /// <summary> /// Stop execution of a Step Functions workflow. /// </summary> /// <param name="executionArn">The Amazon Resource Name (ARN) of /// the Step Functions execution to stop.</param> /// <returns>A Boolean value indicating the success of the action.</returns> public async Task<bool> StopExecution(string executionArn) { var response = await _amazonStepFunctions.StopExecutionAsync(new StopExecutionRequest { ExecutionArn = executionArn }); return response.HttpStatusCode == System.Net.HttpStatusCode.OK; }
-
有关API详细信息,请参阅 “AWS SDK for Java 2.x API参考 GetActivityTask” 中的。
-
- Kotlin
-
- SDK对于 Kotlin 来说
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 suspend fun getActivityTask(actArn: String?): List<String> { val myList: MutableList<String> = ArrayList() val getActivityTaskRequest = GetActivityTaskRequest { activityArn = actArn } SfnClient { region = "us-east-1" }.use { sfnClient -> val response = sfnClient.getActivityTask(getActivityTaskRequest) myList.add(response.taskToken.toString()) myList.add(response.input.toString()) return myList } }
-
有关API详细信息,请参阅GetActivityTask
中的 Kotlin AWS SDK API 参考。
-
- Python
-
- SDK适用于 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 get_task(self, activity_arn): """ Gets task data for an activity. When a state machine is waiting for the specified activity, a response is returned with data from the state machine. When a state machine is not waiting, this call blocks for 60 seconds. :param activity_arn: The ARN of the activity to get task data for. :return: The task data for the activity. """ try: response = self.stepfunctions_client.get_activity_task( activityArn=activity_arn ) except ClientError as err: logger.error( "Couldn't get a task for activity %s. Here's why: %s: %s", activity_arn, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return response
-
有关API详细信息,请参阅GetActivityTask中的 AWS SDKPython (Boto3) API 参考。
-
DescribeStateMachine
ListActivities