View a markdown version of this page

Use GetGroups with an AWS SDK or CLI - AWS SDK Code Examples

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

Use GetGroups with an AWS SDK or CLI

The following code examples show how to use GetGroups.

CLI
AWS CLI

To retrieve all groups

The following example displays details for all active group.

aws xray get-groups

Output:

{ "Groups": [ { "GroupName": "AdminGroup", "GroupARN": "arn:aws:xray:us-west-2:123456789012:group/AdminGroup/123456789", "FilterExpression": "service(\"example.com\") {fault OR error}" }, { "GroupName": "SDETGroup", "GroupARN": "arn:aws:xray:us-west-2:123456789012:group/SDETGroup/987654321", "FilterExpression": "responsetime > 2" } ] }

For more information, see Configuring Sampling, Groups, and Encryption Settings with the AWS X-Ray API in the AWS X-Ray Developer Guide.

  • For API details, see GetGroups in AWS CLI Command 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.xray.XRayClient; import software.amazon.awssdk.services.xray.model.GetGroupsResponse; import software.amazon.awssdk.services.xray.model.GroupSummary; import software.amazon.awssdk.services.xray.model.XRayException; 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 GetGroups { public static void main(String[] args) { Region region = Region.US_EAST_1; XRayClient xRayClient = XRayClient.builder() .region(region) .build(); getAllGroups(xRayClient); } public static void getAllGroups(XRayClient xRayClient) { try { GetGroupsResponse groupsResponse = xRayClient.getGroups(); List<GroupSummary> groups = groupsResponse.groups(); for (GroupSummary group : groups) { System.out.println("The AWS XRay group name is " + group.groupName()); } } catch (XRayException e) { System.err.println(e.getMessage()); System.exit(1); } } }
  • For API details, see GetGroups 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 getAllGroups() { XRayClient.fromEnvironment { region = "us-east-1" }.use { xRayClient -> val response = xRayClient.getGroups(GetGroupsRequest {}) response.groups?.forEach { group -> println("The AWS X-Ray group name is ${group.groupName}") } } }
  • For API details, see GetGroups in AWS SDK for Kotlin API reference.