文件範例儲存庫中有更多 AWS SDK可用的範例。 AWS SDK
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用 SDK for Kotlin 路由 53 網域註冊範例
下列程式碼範例示範如何使用 for Kotlin 搭配 Route 53 網域註冊來執行 AWS SDK動作和實作常見案例。
基本知識是程式碼範例,示範如何在服務內執行基本操作。
Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然動作會示範如何呼叫個別服務函數,但您可以在相關案例中查看內容中的動作。
每個範例都包含完整原始程式碼的連結,您可以在其中找到如何在內容中設定和執行程式碼的指示。
開始使用
下列程式碼範例示範如何開始使用 Route 53 網域註冊。
- SDK 適用於 Kotlin
-
注意
還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 /** 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}") } } }
-
如需API詳細資訊,請參閱ListPrices
中的 AWS SDK for Kotlin API參考 。
-
基本概念
以下程式碼範例顯示做法:
列出目前網域和過去一年的操作。
檢視過去一年的帳單和網域類型對應的價格。
取得網域建議。
檢查網域的可用性和可轉移性。
或者,要求網域註冊。
取得操作詳細資訊。
或者,取得網域詳細資訊。
- SDK 適用於 Kotlin
-
注意
還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 /** 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}") } } }
-
如需API詳細資訊,請參閱 中的下列 AWS SDK Kotlin API參考主題。
-
動作
下列程式碼範例示範如何使用 CheckDomainAvailability
。
- SDK 適用於 Kotlin
-
注意
還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 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}") } }
-
如需API詳細資訊,請參閱CheckDomainAvailability
中的 AWS SDK for Kotlin API參考 。
-
下列程式碼範例示範如何使用 CheckDomainTransferability
。
- SDK 適用於 Kotlin
-
注意
還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 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}") } }
-
如需API詳細資訊,請參閱CheckDomainTransferability
中的 AWS SDK for Kotlin API參考。
-
下列程式碼範例示範如何使用 GetDomainDetail
。
- SDK 適用於 Kotlin
-
注意
還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 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}") } }
-
如需API詳細資訊,請參閱GetDomainDetail
中的 AWS SDK for Kotlin API參考。
-
下列程式碼範例示範如何使用 GetDomainSuggestions
。
- SDK 適用於 Kotlin
-
注意
還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 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(" ") } } }
-
如需API詳細資訊,請參閱GetDomainSuggestions
中的 AWS SDK for Kotlin API參考。
-
下列程式碼範例示範如何使用 GetOperationDetail
。
- SDK 適用於 Kotlin
-
注意
還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 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}") } }
-
如需API詳細資訊,請參閱GetOperationDetail
中的 AWS SDK for Kotlin API參考。
-
下列程式碼範例示範如何使用 ListDomains
。
- SDK 適用於 Kotlin
-
注意
還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 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}") } } }
-
如需API詳細資訊,請參閱ListDomains
中的 AWS SDK for Kotlin API參考。
-
下列程式碼範例示範如何使用 ListOperations
。
- SDK 適用於 Kotlin
-
注意
還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 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}") } } }
-
如需API詳細資訊,請參閱ListOperations
中的 AWS SDK for Kotlin API參考。
-
下列程式碼範例示範如何使用 ListPrices
。
- SDK 適用於 Kotlin
-
注意
還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 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}") } } }
-
如需API詳細資訊,請參閱ListPrices
中的 AWS SDK for Kotlin API參考。
-
下列程式碼範例示範如何使用 RegisterDomain
。
- SDK 適用於 Kotlin
-
注意
還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 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 } }
-
如需API詳細資訊,請參閱RegisterDomain
中的 AWS SDK for Kotlin API參考。
-
下列程式碼範例示範如何使用 ViewBilling
。
- SDK 適用於 Kotlin
-
注意
還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 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}") } } }
-
如需API詳細資訊,請參閱ViewBilling
中的 AWS SDK for Kotlin API參考。
-