AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
StartExecution
搭配使用 AWS SDK
以下代码示例演示如何使用 StartExecution
。
操作示例是大型程序的代码摘录,必须在上下文中运行。在以下代码示例中,您可以查看此操作的上下文:
- .NET
-
- AWS SDK for .NET
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 /// <summary> /// Start execution of an AWS Step Functions state machine. /// </summary> /// <param name="executionName">The name to use for the execution.</param> /// <param name="executionJson">The JSON string to pass for execution.</param> /// <param name="stateMachineArn">The Amazon Resource Name (ARN) of the /// Step Functions state machine.</param> /// <returns>The Amazon Resource Name (ARN) of the AWS Step Functions /// execution.</returns> public async Task<string> StartExecutionAsync(string executionJson, string stateMachineArn) { var executionRequest = new StartExecutionRequest { Input = executionJson, StateMachineArn = stateMachineArn }; var response = await _amazonStepFunctions.StartExecutionAsync(executionRequest); return response.ExecutionArn; }
-
有关API详细信息,请参阅 “AWS SDK for .NET API参考 StartExecution” 中的。
-
- Java
-
- SDK适用于 Java 2.x
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 public static String startWorkflow(SfnClient sfnClient, String stateMachineArn, String jsonEx) { UUID uuid = UUID.randomUUID(); String uuidValue = uuid.toString(); try { StartExecutionRequest executionRequest = StartExecutionRequest.builder() .input(jsonEx) .stateMachineArn(stateMachineArn) .name(uuidValue) .build(); StartExecutionResponse response = sfnClient.startExecution(executionRequest); return response.executionArn(); } catch (SfnException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return ""; }
-
有关API详细信息,请参阅 “AWS SDK for Java 2.x API参考 StartExecution” 中的。
-
- JavaScript
-
- SDK对于 JavaScript (v3)
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 import { SFNClient, StartExecutionCommand } from "@aws-sdk/client-sfn"; /** * @param {{ sfnClient: SFNClient, stateMachineArn: string }} config */ export async function startExecution({ sfnClient, stateMachineArn }) { const response = await sfnClient.send( new StartExecutionCommand({ stateMachineArn, }), ); console.log(response); // Example response: // { // '$metadata': { // httpStatusCode: 200, // requestId: '202a9309-c16a-454b-adeb-c4d19afe3bf2', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // }, // executionArn: 'arn:aws:states:us-east-1:000000000000:execution:MyStateMachine:aaaaaaaa-f787-49fb-a20c-1b61c64eafe6', // startDate: 2024-01-04T15:54:08.362Z // } return response; } // Call function if run directly import { fileURLToPath } from "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { startExecution({ sfnClient: new SFNClient({}), stateMachineArn: "ARN" }); }
-
有关API详细信息,请参阅 “AWS SDK for JavaScript API参考 StartExecution” 中的。
-
- Kotlin
-
- SDK对于 Kotlin 来说
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 suspend fun startWorkflow( stateMachineArnVal: String?, jsonEx: String?, ): String? { val uuid = UUID.randomUUID() val uuidValue = uuid.toString() val executionRequest = StartExecutionRequest { input = jsonEx stateMachineArn = stateMachineArnVal name = uuidValue } SfnClient { region = "us-east-1" }.use { sfnClient -> val response = sfnClient.startExecution(executionRequest) return response.executionArn } }
-
有关API详细信息,请参阅StartExecution
中的 Kotlin AWS SDK API 参考。
-
- Python
-
- SDK适用于 Python (Boto3)
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 class StateMachine: """Encapsulates Step Functions state machine actions.""" def __init__(self, stepfunctions_client): """ :param stepfunctions_client: A Boto3 Step Functions client. """ self.stepfunctions_client = stepfunctions_client def start(self, state_machine_arn, run_input): """ Start a run of a state machine with a specified input. A run is also known as an "execution" in Step Functions. :param state_machine_arn: The ARN of the state machine to run. :param run_input: The input to the state machine, in JSON format. :return: The ARN of the run. This can be used to get information about the run, including its current status and final output. """ try: response = self.stepfunctions_client.start_execution( stateMachineArn=state_machine_arn, input=run_input ) except ClientError as err: logger.error( "Couldn't start state machine %s. Here's why: %s: %s", state_machine_arn, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return response["executionArn"]
-
有关API详细信息,请参阅StartExecution中的 AWS SDKPython (Boto3) API 参考。
-
SendTaskSuccess
场景