View a markdown version of this page

DeleteGroup 搭配 AWS SDK 或 CLI 使用 - AWS SDK 程式碼範例

文件 AWS 開發套件範例 GitHub 儲存庫中有更多可用的 AWS SDK 範例

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

DeleteGroup 搭配 AWS SDK 或 CLI 使用

下列程式碼範例示範如何使用 DeleteGroup

CLI
AWS CLI

刪除群組

以下 delete-group 範例會刪除指定的群組資源。

aws xray delete-group \ --group-name "AdminGroup" \ --group-arn "arn:aws:xray:us-east-2:123456789012:group/AdminGroup/123456789"

此命令不會產生輸出。

如需詳細資訊,請參閱《AWS X-Ray 開發人員指南》中的使用 X-Ray API 設定取樣、群組和加密設定AWS

  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 DeleteGroup

Java
SDK for Java 2.x
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.xray.XRayClient; import software.amazon.awssdk.services.xray.model.DeleteGroupRequest; 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 DeleteGroup { public static void main(String[] args) { final String usage = """ Usage: <groupName> Where: groupName - The name of the group to delete\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(); deleteSpecificGroup(xRayClient, groupName); } public static void deleteSpecificGroup(XRayClient xRayClient, String groupName) { try { DeleteGroupRequest groupRequest = DeleteGroupRequest.builder() .groupName(groupName) .build(); xRayClient.deleteGroup(groupRequest); System.out.println(groupName + " was deleted!"); } catch (XRayException e) { System.err.println(e.getMessage()); System.exit(1); } } }
  • 如需 API 詳細資訊,請參閱《AWS SDK for Java 2.x API 參考》中的 DeleteGroup

Kotlin
適用於 Kotlin 的 SDK
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

suspend fun deleteSpecificGroup(groupNameVal: String) { val groupRequest = DeleteGroupRequest { groupName = groupNameVal } XRayClient.fromEnvironment { region = "us-east-1" }.use { xRayClient -> xRayClient.deleteGroup(groupRequest) println("$groupNameVal was deleted!") } }
  • 如需 API 詳細資訊,請參閱《適用於 AWS Kotlin 的 SDK API 參考》中的 DeleteGroup