文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
ListStateMachines
搭配 a AWS SDK 使用
下列程式碼範例示範如何使用 ListStateMachines
。
動作範例是大型程式的程式碼摘錄,必須在內容中執行。您可以在下列程式碼範例的內容中看到此動作:
- .NET
-
- AWS SDK for .NET
-
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 /// <summary> /// Retrieve a list of Step Functions state machines. /// </summary> /// <returns>A list of StateMachineListItem objects.</returns> public async Task<List<StateMachineListItem>> ListStateMachinesAsync() { var stateMachines = new List<StateMachineListItem>(); var listStateMachinesPaginator = _amazonStepFunctions.Paginators.ListStateMachines(new ListStateMachinesRequest()); await foreach (var response in listStateMachinesPaginator.Responses) { stateMachines.AddRange(response.StateMachines); } return stateMachines; }
-
如需 API 詳細資訊,請參閱 ListStateMachines AWS SDK for .NET 參考中的 API。
-
- Java
-
- Java 2.x 的 SDK
-
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.sfn.SfnClient; import software.amazon.awssdk.services.sfn.model.ListStateMachinesResponse; import software.amazon.awssdk.services.sfn.model.SfnException; import software.amazon.awssdk.services.sfn.model.StateMachineListItem; import java.util.List; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class ListStateMachines { public static void main(String[] args) { Region region = Region.US_EAST_1; SfnClient sfnClient = SfnClient.builder() .region(region) .build(); listMachines(sfnClient); sfnClient.close(); } public static void listMachines(SfnClient sfnClient) { try { ListStateMachinesResponse response = sfnClient.listStateMachines(); List<StateMachineListItem> machines = response.stateMachines(); for (StateMachineListItem machine : machines) { System.out.println("The name of the state machine is: " + machine.name()); System.out.println("The ARN value is : " + machine.stateMachineArn()); } } catch (SfnException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } } }
-
如需 API 詳細資訊,請參閱 ListStateMachines AWS SDK for Java 2.x 參考中的 API。
-
- Kotlin
-
- Kotlin 的 SDK
-
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 import aws.sdk.kotlin.services.sfn.SfnClient import aws.sdk.kotlin.services.sfn.model.ListStateMachinesRequest /** Before running this Kotlin code example, set up your development environment, including your credentials. For more information, see the following documentation topic: https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/setup.html */ suspend fun main() { println(DASHES) println("Welcome to the AWS Step Functions Hello example.") println("Lets list up to ten of your state machines:") println(DASHES) listMachines() } suspend fun listMachines() { SfnClient { region = "us-east-1" }.use { sfnClient -> val response = sfnClient.listStateMachines(ListStateMachinesRequest {}) response.stateMachines?.forEach { machine -> println("The name of the state machine is ${machine.name}") println("The ARN value is ${machine.stateMachineArn}") } } }
-
如需 API 詳細資訊,請參閱 ListStateMachines
AWS for Kotlin SDK 參考中的 API。
-
- Python
-
- Python 的 SDK (Boto3)
-
注意
還有更多 on 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 find(self, name): """ Find a state machine by name. This requires listing the state machines until one is found with a matching name. :param name: The name of the state machine to search for. :return: The ARN of the state machine if found; otherwise, None. """ try: paginator = self.stepfunctions_client.get_paginator("list_state_machines") for page in paginator.paginate(): for state_machine in page.get("stateMachines", []): if state_machine["name"] == name: return state_machine["stateMachineArn"] except ClientError as err: logger.error( "Couldn't list state machines. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise
-
如需 API 詳細資訊,請參閱 ListStateMachines AWS SDK for Python (Boto3) Word 參考中的 API。
-
ListExecutions
SendTaskSuccess