文档 AWS SDK 示例 GitHub 存储库中还有更多 S AWS DK 示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
GetGroups与 AWS SDK 或 CLI 配合使用
以下代码示例演示如何使用 GetGroups。
- CLI
-
- AWS CLI
-
检索所有组
以下示例显示所有活动组的详细信息。
aws xray get-groups输出:
{ "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" } ] }有关更多信息,请参阅《X-Ray 开发人员指南》中的 “使用 AWS X-Ray API 配置采样、分组和加密设置”。AWS
-
有关 API 的详细信息,请参阅AWS CLI 命令参考GetGroups
中的。
-
- Java
-
- 适用于 Java 的 SDK 2.x
-
注意
还有更多相关信息 GitHub。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 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); } } }-
有关 API 的详细信息,请参阅 AWS SDK for Java 2.x API 参考GetGroups中的。
-
- Kotlin
-
- 适用于 Kotlin 的 SDK
-
注意
还有更多相关信息 GitHub。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 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}") } } }-
有关 API 的详细信息,请参阅适用GetGroups
于 K otlin 的AWS SDK API 参考。
-
DeleteSamplingRule
GetSamplingRules