Route 53 domain registration examples using SDK for Kotlin - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Route 53 domain registration examples using SDK for Kotlin

The following code examples show you how to perform actions and implement common scenarios by using the AWS SDK for Kotlin with Route 53 domain registration.

Basics are code examples that show you how to perform the essential operations within a service.

Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.

Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.

Get started

The following code examples show how to get started using Route 53 domain registration.

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.

/** Before running this Kotlin 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-kotlin/latest/developer-guide/setup.html */ suspend fun main(args: Array<String>) { val usage = """ Usage: <domainType> Where: domainType - The domain type (for example, com). """ if (args.size != 1) { println(usage) exitProcess(0) } val domainType = args[0] println("Invokes ListPrices using a Paginated method.") listPricesPaginated(domainType) } suspend fun listPricesPaginated(domainType: String) { val pricesRequest = ListPricesRequest { maxItems = 10 tld = domainType } Route53DomainsClient { region = "us-east-1" }.use { route53DomainsClient -> route53DomainsClient .listPricesPaginated(pricesRequest) .transform { it.prices?.forEach { obj -> emit(obj) } } .collect { pr -> println("Registration: ${pr.registrationPrice} ${pr.registrationPrice?.currency}") println("Renewal: ${pr.renewalPrice?.price} ${pr.renewalPrice?.currency}") println("Transfer: ${pr.transferPrice?.price} ${pr.transferPrice?.currency}") println("Restoration: ${pr.restorationPrice?.price} ${pr.restorationPrice?.currency}") } } }
  • For API details, see ListPrices in AWS SDK for Kotlin API reference.

Basics

The following code example shows how to:

  • List current domains, and list operations in the past year.

  • View billing for the past year, and view prices for domain types.

  • Get domain suggestions.

  • Check domain availability and transferability.

  • Optionally, request a domain registration.

  • Get an operation detail.

  • Optionally, get a domain detail.

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.

/** Before running this Kotlin 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-kotlin/latest/developer-guide/setup.html This Kotlin code example performs the following operations: 1. List current domains. 2. List operations in the past year. 3. View billing for the account in the past year. 4. View prices for domain types. 5. Get domain suggestions. 6. Check domain availability. 7. Check domain transferability. 8. Request a domain registration. 9. Get operation details. 10. Optionally, get domain details. */ val DASHES: String = String(CharArray(80)).replace("\u0000", "-") suspend fun main(args: Array<String>) { val usage = """ Usage: <domainType> <phoneNumber> <email> <domainSuggestion> <firstName> <lastName> <city> Where: domainType - The domain type (for example, com). phoneNumber - The phone number to use (for example, +1.2065550100) email - The email address to use. domainSuggestion - The domain suggestion (for example, findmy.example). firstName - The first name to use to register a domain. lastName - The last name to use to register a domain. city - The city to use to register a domain. """ if (args.size != 7) { println(usage) exitProcess(1) } val domainType = args[0] val phoneNumber = args[1] val email = args[2] val domainSuggestion = args[3] val firstName = args[4] val lastName = args[5] val city = args[6] println(DASHES) println("Welcome to the Amazon Route 53 domains example scenario.") println(DASHES) println(DASHES) println("1. List current domains.") listDomains() println(DASHES) println(DASHES) println("2. List operations in the past year.") listOperations() println(DASHES) println(DASHES) println("3. View billing for the account in the past year.") listBillingRecords() println(DASHES) println(DASHES) println("4. View prices for domain types.") listAllPrices(domainType) println(DASHES) println(DASHES) println("5. Get domain suggestions.") listDomainSuggestions(domainSuggestion) println(DASHES) println(DASHES) println("6. Check domain availability.") checkDomainAvailability(domainSuggestion) println(DASHES) println(DASHES) println("7. Check domain transferability.") checkDomainTransferability(domainSuggestion) println(DASHES) println(DASHES) println("8. Request a domain registration.") val opId = requestDomainRegistration(domainSuggestion, phoneNumber, email, firstName, lastName, city) println(DASHES) println(DASHES) println("9. Get operation details.") getOperationalDetail(opId) println(DASHES) println(DASHES) println("10. Get domain details.") println("Note: You must have a registered domain to get details.") println("Otherwise an exception is thrown that states ") println("Domain xxxxxxx not found in xxxxxxx account.") getDomainDetails(domainSuggestion) println(DASHES) } suspend fun getDomainDetails(domainSuggestion: String?) { val detailRequest = GetDomainDetailRequest { domainName = domainSuggestion } Route53DomainsClient { region = "us-east-1" }.use { route53DomainsClient -> val response = route53DomainsClient.getDomainDetail(detailRequest) println("The contact first name is ${response.registrantContact?.firstName}") println("The contact last name is ${response.registrantContact?.lastName}") println("The contact org name is ${response.registrantContact?.organizationName}") } } suspend fun getOperationalDetail(opId: String?) { val detailRequest = GetOperationDetailRequest { operationId = opId } Route53DomainsClient { region = "us-east-1" }.use { route53DomainsClient -> val response = route53DomainsClient.getOperationDetail(detailRequest) println("Operation detail message is ${response.message}") } } suspend fun requestDomainRegistration( domainSuggestion: String?, phoneNumberVal: String?, emailVal: String?, firstNameVal: String?, lastNameVal: String?, cityVal: String?, ): String? { val contactDetail = ContactDetail { contactType = ContactType.Company state = "LA" countryCode = CountryCode.In email = emailVal firstName = firstNameVal lastName = lastNameVal city = cityVal phoneNumber = phoneNumberVal organizationName = "My Org" addressLine1 = "My Address" zipCode = "123 123" } val domainRequest = RegisterDomainRequest { adminContact = contactDetail registrantContact = contactDetail techContact = contactDetail domainName = domainSuggestion autoRenew = true durationInYears = 1 } Route53DomainsClient { region = "us-east-1" }.use { route53DomainsClient -> val response = route53DomainsClient.registerDomain(domainRequest) println("Registration requested. Operation Id: ${response.operationId}") return response.operationId } } suspend fun checkDomainTransferability(domainSuggestion: String?) { val transferabilityRequest = CheckDomainTransferabilityRequest { domainName = domainSuggestion } Route53DomainsClient { region = "us-east-1" }.use { route53DomainsClient -> val response = route53DomainsClient.checkDomainTransferability(transferabilityRequest) println("Transferability: ${response.transferability?.transferable}") } } suspend fun checkDomainAvailability(domainSuggestion: String) { val availabilityRequest = CheckDomainAvailabilityRequest { domainName = domainSuggestion } Route53DomainsClient { region = "us-east-1" }.use { route53DomainsClient -> val response = route53DomainsClient.checkDomainAvailability(availabilityRequest) println("$domainSuggestion is ${response.availability}") } } suspend fun listDomainSuggestions(domainSuggestion: String?) { val suggestionsRequest = GetDomainSuggestionsRequest { domainName = domainSuggestion suggestionCount = 5 onlyAvailable = true } Route53DomainsClient { region = "us-east-1" }.use { route53DomainsClient -> val response = route53DomainsClient.getDomainSuggestions(suggestionsRequest) response.suggestionsList?.forEach { suggestion -> println("Suggestion Name: ${suggestion.domainName}") println("Availability: ${suggestion.availability}") println(" ") } } } suspend fun listAllPrices(domainType: String?) { val pricesRequest = ListPricesRequest { tld = domainType } Route53DomainsClient { region = "us-east-1" }.use { route53DomainsClient -> route53DomainsClient .listPricesPaginated(pricesRequest) .transform { it.prices?.forEach { obj -> emit(obj) } } .collect { pr -> println("Registration: ${pr.registrationPrice} ${pr.registrationPrice?.currency}") println("Renewal: ${pr.renewalPrice?.price} ${pr.renewalPrice?.currency}") println("Transfer: ${pr.transferPrice?.price} ${pr.transferPrice?.currency}") println("Restoration: ${pr.restorationPrice?.price} ${pr.restorationPrice?.currency}") } } } 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}") } } } suspend fun listOperations() { val currentDate = Date() var localDateTime = currentDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime() val zoneOffset = ZoneOffset.of("+01:00") localDateTime = localDateTime.minusYears(1) val myTime: java.time.Instant? = localDateTime.toInstant(zoneOffset) val time2: Instant? = myTime?.let { Instant(it) } val operationsRequest = ListOperationsRequest { submittedSince = time2 } Route53DomainsClient { region = "us-east-1" }.use { route53DomainsClient -> route53DomainsClient .listOperationsPaginated(operationsRequest) .transform { it.operations?.forEach { obj -> emit(obj) } } .collect { content -> println("Operation Id: ${content.operationId}") println("Status: ${content.status}") println("Date: ${content.submittedDate}") } } } suspend fun listDomains() { Route53DomainsClient { region = "us-east-1" }.use { route53DomainsClient -> route53DomainsClient .listDomainsPaginated(ListDomainsRequest {}) .transform { it.domains?.forEach { obj -> emit(obj) } } .collect { content -> println("The domain name is ${content.domainName}") } } }

Actions

The following code example shows how to use CheckDomainAvailability.

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 checkDomainAvailability(domainSuggestion: String) { val availabilityRequest = CheckDomainAvailabilityRequest { domainName = domainSuggestion } Route53DomainsClient { region = "us-east-1" }.use { route53DomainsClient -> val response = route53DomainsClient.checkDomainAvailability(availabilityRequest) println("$domainSuggestion is ${response.availability}") } }

The following code example shows how to use CheckDomainTransferability.

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 checkDomainTransferability(domainSuggestion: String?) { val transferabilityRequest = CheckDomainTransferabilityRequest { domainName = domainSuggestion } Route53DomainsClient { region = "us-east-1" }.use { route53DomainsClient -> val response = route53DomainsClient.checkDomainTransferability(transferabilityRequest) println("Transferability: ${response.transferability?.transferable}") } }

The following code example shows how to use GetDomainDetail.

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 getDomainDetails(domainSuggestion: String?) { val detailRequest = GetDomainDetailRequest { domainName = domainSuggestion } Route53DomainsClient { region = "us-east-1" }.use { route53DomainsClient -> val response = route53DomainsClient.getDomainDetail(detailRequest) println("The contact first name is ${response.registrantContact?.firstName}") println("The contact last name is ${response.registrantContact?.lastName}") println("The contact org name is ${response.registrantContact?.organizationName}") } }
  • For API details, see GetDomainDetail in AWS SDK for Kotlin API reference.

The following code example shows how to use GetDomainSuggestions.

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 listDomainSuggestions(domainSuggestion: String?) { val suggestionsRequest = GetDomainSuggestionsRequest { domainName = domainSuggestion suggestionCount = 5 onlyAvailable = true } Route53DomainsClient { region = "us-east-1" }.use { route53DomainsClient -> val response = route53DomainsClient.getDomainSuggestions(suggestionsRequest) response.suggestionsList?.forEach { suggestion -> println("Suggestion Name: ${suggestion.domainName}") println("Availability: ${suggestion.availability}") println(" ") } } }

The following code example shows how to use GetOperationDetail.

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 getOperationalDetail(opId: String?) { val detailRequest = GetOperationDetailRequest { operationId = opId } Route53DomainsClient { region = "us-east-1" }.use { route53DomainsClient -> val response = route53DomainsClient.getOperationDetail(detailRequest) println("Operation detail message is ${response.message}") } }

The following code example shows how to use ListDomains.

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 listDomains() { Route53DomainsClient { region = "us-east-1" }.use { route53DomainsClient -> route53DomainsClient .listDomainsPaginated(ListDomainsRequest {}) .transform { it.domains?.forEach { obj -> emit(obj) } } .collect { content -> println("The domain name is ${content.domainName}") } } }
  • For API details, see ListDomains in AWS SDK for Kotlin API reference.

The following code example shows how to use ListOperations.

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 listOperations() { val currentDate = Date() var localDateTime = currentDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime() val zoneOffset = ZoneOffset.of("+01:00") localDateTime = localDateTime.minusYears(1) val myTime: java.time.Instant? = localDateTime.toInstant(zoneOffset) val time2: Instant? = myTime?.let { Instant(it) } val operationsRequest = ListOperationsRequest { submittedSince = time2 } Route53DomainsClient { region = "us-east-1" }.use { route53DomainsClient -> route53DomainsClient .listOperationsPaginated(operationsRequest) .transform { it.operations?.forEach { obj -> emit(obj) } } .collect { content -> println("Operation Id: ${content.operationId}") println("Status: ${content.status}") println("Date: ${content.submittedDate}") } } }
  • For API details, see ListOperations in AWS SDK for Kotlin API reference.

The following code example shows how to use ListPrices.

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 listAllPrices(domainType: String?) { val pricesRequest = ListPricesRequest { tld = domainType } Route53DomainsClient { region = "us-east-1" }.use { route53DomainsClient -> route53DomainsClient .listPricesPaginated(pricesRequest) .transform { it.prices?.forEach { obj -> emit(obj) } } .collect { pr -> println("Registration: ${pr.registrationPrice} ${pr.registrationPrice?.currency}") println("Renewal: ${pr.renewalPrice?.price} ${pr.renewalPrice?.currency}") println("Transfer: ${pr.transferPrice?.price} ${pr.transferPrice?.currency}") println("Restoration: ${pr.restorationPrice?.price} ${pr.restorationPrice?.currency}") } } }
  • For API details, see ListPrices in AWS SDK for Kotlin API reference.

The following code example shows how to use RegisterDomain.

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 requestDomainRegistration( domainSuggestion: String?, phoneNumberVal: String?, emailVal: String?, firstNameVal: String?, lastNameVal: String?, cityVal: String?, ): String? { val contactDetail = ContactDetail { contactType = ContactType.Company state = "LA" countryCode = CountryCode.In email = emailVal firstName = firstNameVal lastName = lastNameVal city = cityVal phoneNumber = phoneNumberVal organizationName = "My Org" addressLine1 = "My Address" zipCode = "123 123" } val domainRequest = RegisterDomainRequest { adminContact = contactDetail registrantContact = contactDetail techContact = contactDetail domainName = domainSuggestion autoRenew = true durationInYears = 1 } Route53DomainsClient { region = "us-east-1" }.use { route53DomainsClient -> val response = route53DomainsClient.registerDomain(domainRequest) println("Registration requested. Operation Id: ${response.operationId}") return response.operationId } }
  • For API details, see RegisterDomain in AWS SDK for Kotlin API reference.

The following code example shows how to use ViewBilling.

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.