本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用 ViewBilling 用 Amazon SDK 或 CLI
以下代码示例显示了如何使用 ViewBilling。
操作示例是大型程序的代码摘录,必须在上下文中运行。在以下代码示例中,您可以查看此操作的上下文:
- .NET
-
- 适用于 .NET 的 Amazon SDK
-
注意
还有更多关于 GitHub。在 Amazon 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 /// <summary> /// View billing records for the account between a start and end date. /// </summary> /// <param name="startDate">The start date for billing results.</param> /// <param name="endDate">The end date for billing results.</param> /// <returns>A collection of billing records.</returns> public async Task<List<BillingRecord>> ViewBilling(DateTime startDate, DateTime endDate) { var results = new List<BillingRecord>(); var paginateBilling = _amazonRoute53Domains.Paginators.ViewBilling( new ViewBillingRequest() { Start = startDate, End = endDate }); // Get the entire list using the paginator. await foreach (var billingRecords in paginateBilling.BillingRecords) { results.Add(billingRecords); } return results; }-
有关 API 的详细信息,请参阅 ViewBilling 在 适用于 .NET 的 Amazon SDK API 参考。
-
- CLI
-
- Amazon CLI
-
获取当前域名注册费用的账单信息 Amazon 帐户
以下
view-billing示例返回当前账户在 2018 年 1 月 1 日(Unix 时间为 1514764800)和 2019 年 12 月 31 日午夜(Unix 时间为 1577836800)这段时间内所有与域名相关的账单记录。此命令仅在
us-east-1区域中运行。如果您的默认区域设置为us-east-1,则可以省略region参数。aws route53domains view-billing \ --regionus-east-1\ --start-time1514764800\ --end-time1577836800输出:
{ "BillingRecords": [ { "DomainName": "example.com", "Operation": "RENEW_DOMAIN", "InvoiceId": "149962827", "BillDate": 1536618063.181, "Price": 12.0 }, { "DomainName": "example.com", "Operation": "RENEW_DOMAIN", "InvoiceId": "290913289", "BillDate": 1568162630.884, "Price": 12.0 } ] }欲了解更多信息,请参阅 下载域名账单报告 在 亚马逊 Route 53 开发者指南。
-
有关 API 的详细信息,请参阅 ViewBilling
在 Amazon CLI 命令参考。
-
- Java
-
- 适用于 Java 的 SDK 2.x
-
注意
还有更多关于 GitHub。在 Amazon 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 public static void listBillingRecords(Route53DomainsClient route53DomainsClient) { try { Date currentDate = new Date(); LocalDateTime localDateTime = currentDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); ZoneOffset zoneOffset = ZoneOffset.of("+01:00"); LocalDateTime localDateTime2 = localDateTime.minusYears(1); Instant myStartTime = localDateTime2.toInstant(zoneOffset); Instant myEndTime = localDateTime.toInstant(zoneOffset); ViewBillingRequest viewBillingRequest = ViewBillingRequest.builder() .start(myStartTime) .end(myEndTime) .build(); ViewBillingIterable listRes = route53DomainsClient.viewBillingPaginator(viewBillingRequest); listRes.stream() .flatMap(r -> r.billingRecords().stream()) .forEach(content -> System.out.println(" Bill Date:: " + content.billDate() + " Operation: " + content.operationAsString() + " Price: " + content.price())); } catch (Route53Exception e) { System.err.println(e.getMessage()); System.exit(1); } }-
有关 API 的详细信息,请参阅 ViewBilling 在 Amazon SDK for Java 2.x API 参考。
-
- Kotlin
-
- 适用于 Kotlin 的 SDK
-
注意
还有更多关于 GitHub。在 Amazon 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 suspend fun listBillingRecords() { val currentDate = Date() val localDateTime = currentDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime() val zoneOffset = ZoneOffset.of("+01:00") val localDateTime2 = localDateTime.minusYears(1) val myStartTime = localDateTime2.toInstant(zoneOffset) val myEndTime = localDateTime.toInstant(zoneOffset) val timeStart: Instant? = myStartTime?.let { Instant(it) } val timeEnd: Instant? = myEndTime?.let { Instant(it) } val viewBillingRequest = ViewBillingRequest { start = timeStart end = timeEnd } Route53DomainsClient.fromEnvironment { region = "us-east-1" }.use { route53DomainsClient -> route53DomainsClient .viewBillingPaginated(viewBillingRequest) .transform { it.billingRecords?.forEach { obj -> emit(obj) } } .collect { billing -> println("Bill Date: ${billing.billDate}") println("Operation: ${billing.operation}") println("Price: ${billing.price}") } } }-
有关 API 的详细信息,请参阅 ViewBilling
在 Amazon 适用于 Kotlin 的 SDK API 参考。
-
如需查看完整清单 Amazon SDK 开发者指南和代码示例,请参阅 将 Route 53 与 Amazon SDK。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。