There are more AWS SDK examples available in the AWS Doc SDK Examples
Use CreateGroup with an AWS SDK or CLI
The following code examples show how to use CreateGroup.
- CLI
-
- AWS CLI
-
To create a group
The following
create-groupexample creates a group resource namedAdminGroup. The group gets a filter expression that defines the criteria of the group as a segment related to a specific service causing a fault or an error.aws xray create-group \ --group-name"AdminGroup"\ --filter-expression "service(\"mydomain.com\") {fault OR error}"Output:
{ "GroupName": "AdminGroup", "GroupARN": "arn:aws:xray:us-west-2:123456789012:group/AdminGroup/123456789", "FilterExpression": "service(\"mydomain.com\") {fault OR error}" }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 CreateGroup
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.CreateGroupRequest; import software.amazon.awssdk.services.xray.model.CreateGroupResponse; import software.amazon.awssdk.services.xray.model.XRayException; /** * 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 CreateGroup { public static void main(String[] args) { final String usage = """ Usage: <groupName> Where: groupName - The name of the group to create\s """; if (args.length != 1) { System.out.println(usage); System.exit(1); } String groupName = args[0]; Region region = Region.US_EAST_1; XRayClient xRayClient = XRayClient.builder() .region(region) .build(); createNewGroup(xRayClient, groupName); } public static void createNewGroup(XRayClient xRayClient, String groupName) { try { CreateGroupRequest groupRequest = CreateGroupRequest.builder() .filterExpression("fault = true AND http.url CONTAINS \"example/game\" AND responsetime >= 5") .groupName(groupName) .build(); CreateGroupResponse groupResponse = xRayClient.createGroup(groupRequest); System.out.println("The Group ARN is " + groupResponse.group().groupARN()); } catch (XRayException e) { System.err.println(e.getMessage()); System.exit(1); } } }-
For API details, see CreateGroup 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 createNewGroup(groupNameVal: String?) { val groupRequest = CreateGroupRequest { filterExpression = "fault = true AND http.url CONTAINS \"example/game\" AND responsetime >= 5" groupName = groupNameVal } XRayClient.fromEnvironment { region = "us-east-1" }.use { xRayClient -> val groupResponse = xRayClient.createGroup(groupRequest) println("The Group ARN is " + (groupResponse.group?.groupArn)) } }-
For API details, see CreateGroup
in AWS SDK for Kotlin API reference.
-