Use ViewBilling with an AWS SDK or CLI - Amazon Route 53

Use ViewBilling with an AWS SDK or CLI

The following code examples show how to use ViewBilling.

Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:

.NET
AWS SDK for .NET
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/// <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; }
  • For API details, see ViewBilling in AWS SDK for .NET API Reference.

CLI
AWS CLI

To get billing information for domain registration charges for the current AWS account

The following view-billing command returns all the domain-related billing records for the current account for the period from January 1, 2018 (1514764800 in Unix time) and midnight on December 31, 2019 (1577836800 in Unix time).

This command runs only in the us-east-1 Region. If your default region is set to us-east-1, you can omit the region parameter.

aws route53domains view-billing \ --region us-east-1 \ --start-time 1514764800 \ --end-time 1577836800

Output:

{ "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 } ] }

For more information, see ViewBilling in the Amazon Route 53 API Reference.

  • For API details, see ViewBilling 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.

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); } }
  • For API details, see ViewBilling 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 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 { 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}") } } }
  • For API details, see ViewBilling in AWS SDK for Kotlin API reference.

For a complete list of AWS SDK developer guides and code examples, see Using Route 53 with an AWS SDK. This topic also includes information about getting started and details about previous SDK versions.