Use ListActivities with an AWS SDK or command line tool - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Use ListActivities with an AWS SDK or command line tool

The following code examples show how to use ListActivities.

Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:

.NET
AWS SDK for .NET
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/// <summary> /// List the Step Functions activities for the current account. /// </summary> /// <returns>A list of ActivityListItems.</returns> public async Task<List<ActivityListItem>> ListActivitiesAsync() { var request = new ListActivitiesRequest(); var activities = new List<ActivityListItem>(); do { var response = await _amazonStepFunctions.ListActivitiesAsync(request); if (response.NextToken is not null) { request.NextToken = response.NextToken; } activities.AddRange(response.Activities); } while (request.NextToken is not null); return activities; }
  • For API details, see ListActivities in AWS SDK for .NET API Reference.

Java
SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.sfn.SfnClient; import software.amazon.awssdk.services.sfn.model.ListActivitiesRequest; import software.amazon.awssdk.services.sfn.model.ListActivitiesResponse; import software.amazon.awssdk.services.sfn.model.SfnException; import software.amazon.awssdk.services.sfn.model.ActivityListItem; 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 ListActivities { public static void main(String[] args) { Region region = Region.US_EAST_1; SfnClient sfnClient = SfnClient.builder() .region(region) .build(); listAllActivites(sfnClient); sfnClient.close(); } public static void listAllActivites(SfnClient sfnClient) { try { ListActivitiesRequest activitiesRequest = ListActivitiesRequest.builder() .maxResults(10) .build(); ListActivitiesResponse response = sfnClient.listActivities(activitiesRequest); List<ActivityListItem> items = response.activities(); for (ActivityListItem item : items) { System.out.println("The activity ARN is " + item.activityArn()); System.out.println("The activity name is " + item.name()); } } catch (SfnException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } } }
  • For API details, see ListActivities in AWS SDK for Java 2.x API Reference.

Kotlin
SDK for Kotlin
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

suspend fun listAllActivites() { val activitiesRequest = ListActivitiesRequest { maxResults = 10 } SfnClient { region = "us-east-1" }.use { sfnClient -> val response = sfnClient.listActivities(activitiesRequest) response.activities?.forEach { item -> println("The activity ARN is ${item.activityArn}") println("The activity name is ${item.name}") } } }
  • For API details, see ListActivities in AWS SDK for Kotlin API reference.

Python
SDK for Python (Boto3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

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 find(self, name): """ Find an activity by name. This requires listing activities until one is found with a matching name. :param name: The name of the activity to search for. :return: If found, the ARN of the activity; otherwise, None. """ try: paginator = self.stepfunctions_client.get_paginator("list_activities") for page in paginator.paginate(): for activity in page.get("activities", []): if activity["name"] == name: return activity["activityArn"] except ClientError as err: logger.error( "Couldn't list activities. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise
  • For API details, see ListActivities in AWS SDK for Python (Boto3) API Reference.