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

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

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

DescribeAccountAttributes 搭配 a AWS SDK 或 CLI 使用

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

CLI
AWS CLI

描述帳戶屬性

下列describe-account-attributes範例會擷取目前 AWS 帳戶的屬性。

aws rds describe-account-attributes

輸出:

{ "AccountQuotas": [ { "Max": 40, "Used": 4, "AccountQuotaName": "DBInstances" }, { "Max": 40, "Used": 0, "AccountQuotaName": "ReservedDBInstances" }, { "Max": 100000, "Used": 40, "AccountQuotaName": "AllocatedStorage" }, { "Max": 25, "Used": 0, "AccountQuotaName": "DBSecurityGroups" }, { "Max": 20, "Used": 0, "AccountQuotaName": "AuthorizationsPerDBSecurityGroup" }, { "Max": 50, "Used": 1, "AccountQuotaName": "DBParameterGroups" }, { "Max": 100, "Used": 3, "AccountQuotaName": "ManualSnapshots" }, { "Max": 20, "Used": 0, "AccountQuotaName": "EventSubscriptions" }, { "Max": 50, "Used": 1, "AccountQuotaName": "DBSubnetGroups" }, { "Max": 20, "Used": 1, "AccountQuotaName": "OptionGroups" }, { "Max": 20, "Used": 6, "AccountQuotaName": "SubnetsPerDBSubnetGroup" }, { "Max": 5, "Used": 0, "AccountQuotaName": "ReadReplicasPerMaster" }, { "Max": 40, "Used": 1, "AccountQuotaName": "DBClusters" }, { "Max": 50, "Used": 0, "AccountQuotaName": "DBClusterParameterGroups" }, { "Max": 5, "Used": 0, "AccountQuotaName": "DBClusterRoles" } ] }
Java
Java 2.x 的 SDK
注意

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

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.rds.RdsClient; import software.amazon.awssdk.services.rds.model.AccountQuota; import software.amazon.awssdk.services.rds.model.RdsException; import software.amazon.awssdk.services.rds.model.DescribeAccountAttributesResponse; 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 DescribeAccountAttributes { public static void main(String[] args) { Region region = Region.US_WEST_2; RdsClient rdsClient = RdsClient.builder() .region(region) .build(); getAccountAttributes(rdsClient); rdsClient.close(); } public static void getAccountAttributes(RdsClient rdsClient) { try { DescribeAccountAttributesResponse response = rdsClient.describeAccountAttributes(); List<AccountQuota> quotasList = response.accountQuotas(); for (AccountQuota quotas : quotasList) { System.out.println("Name is: " + quotas.accountQuotaName()); System.out.println("Max value is " + quotas.max()); } } catch (RdsException e) { System.out.println(e.getLocalizedMessage()); System.exit(1); } } }
Kotlin
Kotlin 的 SDK
注意

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

suspend fun getAccountAttributes() { RdsClient { region = "us-west-2" }.use { rdsClient -> val response = rdsClient.describeAccountAttributes(DescribeAccountAttributesRequest {}) response.accountQuotas?.forEach { quotas -> val response = response.accountQuotas println("Name is: ${quotas.accountQuotaName}") println("Max value is ${quotas.max}") } } }