Aprenda os elementos básicos de registro de domínio do Route 53 com um SDK da AWS
Os exemplos de código a seguir mostram como:
Liste os domínios atuais e as operações do ano passado.
Ver o faturamento do ano passado e os preços dos tipos de domínio.
Receber sugestões de domínio.
Verificar a disponibilidade e a transferibilidade de um domínio.
Opcionalmente, solicitar o registro de um domínio.
Obter os detalhes de uma operação.
Opcionalmente, obtenha os detalhes de um domínio.
- .NET
-
- AWS SDK for .NET
-
nota
Há mais no GitHub. Encontre o exemplo completo e saiba como configurar e executar no Repositório de exemplos de código da AWS
. Execute um cenário interativo em um prompt de comando.
public static class Route53DomainScenario { /* Before running this .NET code example, set up your development environment, including your credentials. This .NET example performs the following tasks: 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. Optionally, request a domain registration. 9. Get an operation detail. 10. Optionally, get a domain detail. */ private static Route53Wrapper _route53Wrapper = null!; private static IConfiguration _configuration = null!; static async Task Main(string[] args) { // Set up dependency injection for the Amazon service. using var host = Host.CreateDefaultBuilder(args) .ConfigureLogging(logging => logging.AddFilter("System", LogLevel.Debug) .AddFilter<DebugLoggerProvider>("Microsoft", LogLevel.Information) .AddFilter<ConsoleLoggerProvider>("Microsoft", LogLevel.Trace)) .ConfigureServices((_, services) => services.AddAWSService<IAmazonRoute53Domains>() .AddTransient<Route53Wrapper>() ) .Build(); _configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("settings.json") // Load settings from .json file. .AddJsonFile("settings.local.json", true) // Optionally, load local settings. .Build(); var logger = LoggerFactory.Create(builder => { builder.AddConsole(); }).CreateLogger(typeof(Route53DomainScenario)); _route53Wrapper = host.Services.GetRequiredService<Route53Wrapper>(); Console.WriteLine(new string('-', 80)); Console.WriteLine("Welcome to the Amazon Route 53 domains example scenario."); Console.WriteLine(new string('-', 80)); try { await ListDomains(); await ListOperations(); await ListBillingRecords(); await ListPrices(); await ListDomainSuggestions(); await CheckDomainAvailability(); await CheckDomainTransferability(); var operationId = await RequestDomainRegistration(); await GetOperationalDetail(operationId); await GetDomainDetails(); } catch (Exception ex) { logger.LogError(ex, "There was a problem executing the scenario."); } Console.WriteLine(new string('-', 80)); Console.WriteLine("The Amazon Route 53 domains example scenario is complete."); Console.WriteLine(new string('-', 80)); } /// <summary> /// List account registered domains. /// </summary> /// <returns>Async task.</returns> private static async Task ListDomains() { Console.WriteLine(new string('-', 80)); Console.WriteLine($"1. List account domains."); var domains = await _route53Wrapper.ListDomains(); for (int i = 0; i < domains.Count; i++) { Console.WriteLine($"\t{i + 1}. {domains[i].DomainName}"); } if (!domains.Any()) { Console.WriteLine("\tNo domains found in this account."); } Console.WriteLine(new string('-', 80)); } /// <summary> /// List domain operations in the past year. /// </summary> /// <returns>Async task.</returns> private static async Task ListOperations() { Console.WriteLine(new string('-', 80)); Console.WriteLine($"2. List account domain operations in the past year."); var operations = await _route53Wrapper.ListOperations( DateTime.Today.AddYears(-1)); for (int i = 0; i < operations.Count; i++) { Console.WriteLine($"\tOperation Id: {operations[i].OperationId}"); Console.WriteLine($"\tStatus: {operations[i].Status}"); Console.WriteLine($"\tDate: {operations[i].SubmittedDate}"); } Console.WriteLine(new string('-', 80)); } /// <summary> /// List billing in the past year. /// </summary> /// <returns>Async task.</returns> private static async Task ListBillingRecords() { Console.WriteLine(new string('-', 80)); Console.WriteLine($"3. View billing for the account in the past year."); var billingRecords = await _route53Wrapper.ViewBilling( DateTime.Today.AddYears(-1), DateTime.Today); for (int i = 0; i < billingRecords.Count; i++) { Console.WriteLine($"\tBill Date: {billingRecords[i].BillDate.ToShortDateString()}"); Console.WriteLine($"\tOperation: {billingRecords[i].Operation}"); Console.WriteLine($"\tPrice: {billingRecords[i].Price}"); } if (!billingRecords.Any()) { Console.WriteLine("\tNo billing records found in this account for the past year."); } Console.WriteLine(new string('-', 80)); } /// <summary> /// List prices for a few domain types. /// </summary> /// <returns>Async task.</returns> private static async Task ListPrices() { Console.WriteLine(new string('-', 80)); Console.WriteLine($"4. View prices for domain types."); var domainTypes = new List<string> { "net", "com", "org", "co" }; var prices = await _route53Wrapper.ListPrices(domainTypes); foreach (var pr in prices) { Console.WriteLine($"\tName: {pr.Name}"); Console.WriteLine($"\tRegistration: {pr.RegistrationPrice?.Price} {pr.RegistrationPrice?.Currency}"); Console.WriteLine($"\tRenewal: {pr.RenewalPrice?.Price} {pr.RenewalPrice?.Currency}"); Console.WriteLine($"\tTransfer: {pr.TransferPrice?.Price} {pr.TransferPrice?.Currency}"); Console.WriteLine($"\tChange Ownership: {pr.ChangeOwnershipPrice?.Price} {pr.ChangeOwnershipPrice?.Currency}"); Console.WriteLine($"\tRestoration: {pr.RestorationPrice?.Price} {pr.RestorationPrice?.Currency}"); Console.WriteLine(); } Console.WriteLine(new string('-', 80)); } /// <summary> /// List domain suggestions for a domain name. /// </summary> /// <returns>Async task.</returns> private static async Task ListDomainSuggestions() { Console.WriteLine(new string('-', 80)); Console.WriteLine($"5. Get domain suggestions."); string? domainName = null; while (domainName == null || string.IsNullOrWhiteSpace(domainName)) { Console.WriteLine($"Enter a domain name to get available domain suggestions."); domainName = Console.ReadLine(); } var suggestions = await _route53Wrapper.GetDomainSuggestions(domainName, true, 5); foreach (var suggestion in suggestions) { Console.WriteLine($"\tSuggestion Name: {suggestion.DomainName}"); Console.WriteLine($"\tAvailability: {suggestion.Availability}"); } Console.WriteLine(new string('-', 80)); } /// <summary> /// Check availability for a domain name. /// </summary> /// <returns>Async task.</returns> private static async Task CheckDomainAvailability() { Console.WriteLine(new string('-', 80)); Console.WriteLine($"6. Check domain availability."); string? domainName = null; while (domainName == null || string.IsNullOrWhiteSpace(domainName)) { Console.WriteLine($"Enter a domain name to check domain availability."); domainName = Console.ReadLine(); } var availability = await _route53Wrapper.CheckDomainAvailability(domainName); Console.WriteLine($"\tAvailability: {availability}"); Console.WriteLine(new string('-', 80)); } /// <summary> /// Check transferability for a domain name. /// </summary> /// <returns>Async task.</returns> private static async Task CheckDomainTransferability() { Console.WriteLine(new string('-', 80)); Console.WriteLine($"7. Check domain transferability."); string? domainName = null; while (domainName == null || string.IsNullOrWhiteSpace(domainName)) { Console.WriteLine($"Enter a domain name to check domain transferability."); domainName = Console.ReadLine(); } var transferability = await _route53Wrapper.CheckDomainTransferability(domainName); Console.WriteLine($"\tTransferability: {transferability}"); Console.WriteLine(new string('-', 80)); } /// <summary> /// Check transferability for a domain name. /// </summary> /// <returns>Async task.</returns> private static async Task<string?> RequestDomainRegistration() { Console.WriteLine(new string('-', 80)); Console.WriteLine($"8. Optionally, request a domain registration."); Console.WriteLine($"\tNote: This example uses domain request settings in settings.json."); Console.WriteLine($"\tTo change the domain registration settings, set the values in that file."); Console.WriteLine($"\tRemember, registering an actual domain will incur an account billing cost."); Console.WriteLine($"\tWould you like to begin a domain registration? (y/n)"); var ynResponse = Console.ReadLine(); if (ynResponse != null && ynResponse.Equals("y", StringComparison.InvariantCultureIgnoreCase)) { string domainName = _configuration["DomainName"]; ContactDetail contact = new ContactDetail(); contact.CountryCode = CountryCode.FindValue(_configuration["Contact:CountryCode"]); contact.ContactType = ContactType.FindValue(_configuration["Contact:ContactType"]); _configuration.GetSection("Contact").Bind(contact); var operationId = await _route53Wrapper.RegisterDomain( domainName, Convert.ToBoolean(_configuration["AutoRenew"]), Convert.ToInt32(_configuration["DurationInYears"]), contact); if (operationId != null) { Console.WriteLine( $"\tRegistration requested. Operation Id: {operationId}"); } return operationId; } Console.WriteLine(new string('-', 80)); return null; } /// <summary> /// Get details for an operation. /// </summary> /// <returns>Async task.</returns> private static async Task GetOperationalDetail(string? operationId) { Console.WriteLine(new string('-', 80)); Console.WriteLine($"9. Get an operation detail."); var operationDetails = await _route53Wrapper.GetOperationDetail(operationId); Console.WriteLine(operationDetails); Console.WriteLine(new string('-', 80)); } /// <summary> /// Optionally, get details for a registered domain. /// </summary> /// <returns>Async task.</returns> private static async Task<string?> GetDomainDetails() { Console.WriteLine(new string('-', 80)); Console.WriteLine($"10. Get details on a domain."); Console.WriteLine($"\tNote: you must have a registered domain to get details."); Console.WriteLine($"\tWould you like to get domain details? (y/n)"); var ynResponse = Console.ReadLine(); if (ynResponse != null && ynResponse.Equals("y", StringComparison.InvariantCultureIgnoreCase)) { string? domainName = null; while (domainName == null) { Console.WriteLine($"\tEnter a domain name to get details."); domainName = Console.ReadLine(); } var domainDetails = await _route53Wrapper.GetDomainDetail(domainName); Console.WriteLine(domainDetails); } Console.WriteLine(new string('-', 80)); return null; } }
Os métodos de wrapper usados pelo cenário para as ações do registro de domínios do Route 53.
public class Route53Wrapper { private readonly IAmazonRoute53Domains _amazonRoute53Domains; private readonly ILogger<Route53Wrapper> _logger; public Route53Wrapper(IAmazonRoute53Domains amazonRoute53Domains, ILogger<Route53Wrapper> logger) { _amazonRoute53Domains = amazonRoute53Domains; _logger = logger; } /// <summary> /// List prices for domain type operations. /// </summary> /// <param name="domainTypes">Domain types to include in the results.</param> /// <returns>The list of domain prices.</returns> public async Task<List<DomainPrice>> ListPrices(List<string> domainTypes) { var results = new List<DomainPrice>(); var paginatePrices = _amazonRoute53Domains.Paginators.ListPrices(new ListPricesRequest()); // Get the entire list using the paginator. await foreach (var prices in paginatePrices.Prices) { results.Add(prices); } return results.Where(p => domainTypes.Contains(p.Name)).ToList(); } /// <summary> /// Check the availability of a domain name. /// </summary> /// <param name="domain">The domain to check for availability.</param> /// <returns>An availability result string.</returns> public async Task<string> CheckDomainAvailability(string domain) { var result = await _amazonRoute53Domains.CheckDomainAvailabilityAsync( new CheckDomainAvailabilityRequest { DomainName = domain } ); return result.Availability.Value; } /// <summary> /// Check the transferability of a domain name. /// </summary> /// <param name="domain">The domain to check for transferability.</param> /// <returns>A transferability result string.</returns> public async Task<string> CheckDomainTransferability(string domain) { var result = await _amazonRoute53Domains.CheckDomainTransferabilityAsync( new CheckDomainTransferabilityRequest { DomainName = domain } ); return result.Transferability.Transferable.Value; } /// <summary> /// Get a list of suggestions for a given domain. /// </summary> /// <param name="domain">The domain to check for suggestions.</param> /// <param name="onlyAvailable">If true, only returns available domains.</param> /// <param name="suggestionCount">The number of suggestions to return. Defaults to the max of 50.</param> /// <returns>A collection of domain suggestions.</returns> public async Task<List<DomainSuggestion>> GetDomainSuggestions(string domain, bool onlyAvailable, int suggestionCount = 50) { var result = await _amazonRoute53Domains.GetDomainSuggestionsAsync( new GetDomainSuggestionsRequest { DomainName = domain, OnlyAvailable = onlyAvailable, SuggestionCount = suggestionCount } ); return result.SuggestionsList; } /// <summary> /// Get details for a domain action operation. /// </summary> /// <param name="operationId">The operational Id.</param> /// <returns>A string describing the operational details.</returns> public async Task<string> GetOperationDetail(string? operationId) { if (operationId == null) return "Unable to get operational details because ID is null."; try { var operationDetails = await _amazonRoute53Domains.GetOperationDetailAsync( new GetOperationDetailRequest { OperationId = operationId } ); var details = $"\tOperation {operationId}:\n" + $"\tFor domain {operationDetails.DomainName} on {operationDetails.SubmittedDate.ToShortDateString()}.\n" + $"\tMessage is {operationDetails.Message}.\n" + $"\tStatus is {operationDetails.Status}.\n"; return details; } catch (AmazonRoute53DomainsException ex) { return $"Unable to get operation details. Here's why: {ex.Message}."; } } /// <summary> /// Initiate a domain registration request. /// </summary> /// <param name="contact">Contact details.</param> /// <param name="domainName">The domain name to register.</param> /// <param name="autoRenew">True if the domain should automatically renew.</param> /// <param name="duration">The duration in years for the domain registration.</param> /// <returns>The operation Id.</returns> public async Task<string?> RegisterDomain(string domainName, bool autoRenew, int duration, ContactDetail contact) { // This example uses the same contact information for admin, registrant, and tech contacts. try { var result = await _amazonRoute53Domains.RegisterDomainAsync( new RegisterDomainRequest() { AdminContact = contact, RegistrantContact = contact, TechContact = contact, DomainName = domainName, AutoRenew = autoRenew, DurationInYears = duration, PrivacyProtectAdminContact = false, PrivacyProtectRegistrantContact = false, PrivacyProtectTechContact = false } ); return result.OperationId; } catch (InvalidInputException) { _logger.LogInformation($"Unable to request registration for domain {domainName}"); return null; } } /// <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; } /// <summary> /// List the domains for the account. /// </summary> /// <returns>A collection of domain summary records.</returns> public async Task<List<DomainSummary>> ListDomains() { var results = new List<DomainSummary>(); var paginateDomains = _amazonRoute53Domains.Paginators.ListDomains( new ListDomainsRequest()); // Get the entire list using the paginator. await foreach (var domain in paginateDomains.Domains) { results.Add(domain); } return results; } /// <summary> /// List operations for the account that are submitted after a specified date. /// </summary> /// <returns>A collection of operation summary records.</returns> public async Task<List<OperationSummary>> ListOperations(DateTime submittedSince) { var results = new List<OperationSummary>(); var paginateOperations = _amazonRoute53Domains.Paginators.ListOperations( new ListOperationsRequest() { SubmittedSince = submittedSince }); // Get the entire list using the paginator. await foreach (var operations in paginateOperations.Operations) { results.Add(operations); } return results; } /// <summary> /// Get details for a domain. /// </summary> /// <returns>A string with detail information about the domain.</returns> public async Task<string> GetDomainDetail(string domainName) { try { var result = await _amazonRoute53Domains.GetDomainDetailAsync( new GetDomainDetailRequest() { DomainName = domainName }); var details = $"\tDomain {domainName}:\n" + $"\tCreated on {result.CreationDate.ToShortDateString()}.\n" + $"\tAdmin contact is {result.AdminContact.Email}.\n" + $"\tAuto-renew is {result.AutoRenew}.\n"; return details; } catch (InvalidInputException) { return $"Domain {domainName} was not found in your account."; } } }
-
Para obter detalhes da API, consulte os tópicos a seguir na Referência da API AWS SDK for .NET.
-
- Java
-
- SDK para Java 2.x
-
nota
Há mais no GitHub. Encontre o exemplo completo e saiba como configurar e executar no Repositório de exemplos de código da AWS
. /** * 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 * * This example uses pagination methods where applicable. For example, to list * domains, the * listDomainsPaginator method is used. For more information about pagination, * see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/pagination.html * * This Java 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. */ public class Route53Scenario { public static final String DASHES = new String(new char[80]).replace("\0", "-"); public static void main(String[] args) { final String usage = """ Usage: <domainType> <phoneNumber> <email> <domainSuggestion> <firstName> <lastName> <city> Where: domainType - The domain type (for example, com).\s phoneNumber - The phone number to use (for example, +91.9966564xxx) email - The email address to use. domainSuggestion - The domain suggestion (for example, findmy.accountants).\s firstName - The first name to use to register a domain.\s lastName - The last name to use to register a domain.\s city - the city to use to register a domain.\s """; if (args.length != 7) { System.out.println(usage); System.exit(1); } String domainType = args[0]; String phoneNumber = args[1]; String email = args[2]; String domainSuggestion = args[3]; String firstName = args[4]; String lastName = args[5]; String city = args[6]; Region region = Region.US_EAST_1; Route53DomainsClient route53DomainsClient = Route53DomainsClient.builder() .region(region) .build(); System.out.println(DASHES); System.out.println("Welcome to the Amazon Route 53 domains example scenario."); System.out.println(DASHES); System.out.println(DASHES); System.out.println("1. List current domains."); listDomains(route53DomainsClient); System.out.println(DASHES); System.out.println(DASHES); System.out.println("2. List operations in the past year."); listOperations(route53DomainsClient); System.out.println(DASHES); System.out.println(DASHES); System.out.println("3. View billing for the account in the past year."); listBillingRecords(route53DomainsClient); System.out.println(DASHES); System.out.println(DASHES); System.out.println("4. View prices for domain types."); listPrices(route53DomainsClient, domainType); System.out.println(DASHES); System.out.println(DASHES); System.out.println("5. Get domain suggestions."); listDomainSuggestions(route53DomainsClient, domainSuggestion); System.out.println(DASHES); System.out.println(DASHES); System.out.println("6. Check domain availability."); checkDomainAvailability(route53DomainsClient, domainSuggestion); System.out.println(DASHES); System.out.println(DASHES); System.out.println("7. Check domain transferability."); checkDomainTransferability(route53DomainsClient, domainSuggestion); System.out.println(DASHES); System.out.println(DASHES); System.out.println("8. Request a domain registration."); String opId = requestDomainRegistration(route53DomainsClient, domainSuggestion, phoneNumber, email, firstName, lastName, city); System.out.println(DASHES); System.out.println(DASHES); System.out.println("9. Get operation details."); getOperationalDetail(route53DomainsClient, opId); System.out.println(DASHES); System.out.println(DASHES); System.out.println("10. Get domain details."); System.out.println("Note: You must have a registered domain to get details."); System.out.println("Otherwise, an exception is thrown that states "); System.out.println("Domain xxxxxxx not found in xxxxxxx account."); getDomainDetails(route53DomainsClient, domainSuggestion); System.out.println(DASHES); } public static void getDomainDetails(Route53DomainsClient route53DomainsClient, String domainSuggestion) { try { GetDomainDetailRequest detailRequest = GetDomainDetailRequest.builder() .domainName(domainSuggestion) .build(); GetDomainDetailResponse response = route53DomainsClient.getDomainDetail(detailRequest); System.out.println("The contact first name is " + response.registrantContact().firstName()); System.out.println("The contact last name is " + response.registrantContact().lastName()); System.out.println("The contact org name is " + response.registrantContact().organizationName()); } catch (Route53Exception e) { System.err.println(e.getMessage()); System.exit(1); } } public static void getOperationalDetail(Route53DomainsClient route53DomainsClient, String operationId) { try { GetOperationDetailRequest detailRequest = GetOperationDetailRequest.builder() .operationId(operationId) .build(); GetOperationDetailResponse response = route53DomainsClient.getOperationDetail(detailRequest); System.out.println("Operation detail message is " + response.message()); } catch (Route53Exception e) { System.err.println(e.getMessage()); System.exit(1); } } public static String requestDomainRegistration(Route53DomainsClient route53DomainsClient, String domainSuggestion, String phoneNumber, String email, String firstName, String lastName, String city) { try { ContactDetail contactDetail = ContactDetail.builder() .contactType(ContactType.COMPANY) .state("LA") .countryCode(CountryCode.IN) .email(email) .firstName(firstName) .lastName(lastName) .city(city) .phoneNumber(phoneNumber) .organizationName("My Org") .addressLine1("My Address") .zipCode("123 123") .build(); RegisterDomainRequest domainRequest = RegisterDomainRequest.builder() .adminContact(contactDetail) .registrantContact(contactDetail) .techContact(contactDetail) .domainName(domainSuggestion) .autoRenew(true) .durationInYears(1) .build(); RegisterDomainResponse response = route53DomainsClient.registerDomain(domainRequest); System.out.println("Registration requested. Operation Id: " + response.operationId()); return response.operationId(); } catch (Route53Exception e) { System.err.println(e.getMessage()); System.exit(1); } return ""; } public static void checkDomainTransferability(Route53DomainsClient route53DomainsClient, String domainSuggestion) { try { CheckDomainTransferabilityRequest transferabilityRequest = CheckDomainTransferabilityRequest.builder() .domainName(domainSuggestion) .build(); CheckDomainTransferabilityResponse response = route53DomainsClient .checkDomainTransferability(transferabilityRequest); System.out.println("Transferability: " + response.transferability().transferable().toString()); } catch (Route53Exception e) { System.err.println(e.getMessage()); System.exit(1); } } public static void checkDomainAvailability(Route53DomainsClient route53DomainsClient, String domainSuggestion) { try { CheckDomainAvailabilityRequest availabilityRequest = CheckDomainAvailabilityRequest.builder() .domainName(domainSuggestion) .build(); CheckDomainAvailabilityResponse response = route53DomainsClient .checkDomainAvailability(availabilityRequest); System.out.println(domainSuggestion + " is " + response.availability().toString()); } catch (Route53Exception e) { System.err.println(e.getMessage()); System.exit(1); } } public static void listDomainSuggestions(Route53DomainsClient route53DomainsClient, String domainSuggestion) { try { GetDomainSuggestionsRequest suggestionsRequest = GetDomainSuggestionsRequest.builder() .domainName(domainSuggestion) .suggestionCount(5) .onlyAvailable(true) .build(); GetDomainSuggestionsResponse response = route53DomainsClient.getDomainSuggestions(suggestionsRequest); List<DomainSuggestion> suggestions = response.suggestionsList(); for (DomainSuggestion suggestion : suggestions) { System.out.println("Suggestion Name: " + suggestion.domainName()); System.out.println("Availability: " + suggestion.availability()); System.out.println(" "); } } catch (Route53Exception e) { System.err.println(e.getMessage()); System.exit(1); } } public static void listPrices(Route53DomainsClient route53DomainsClient, String domainType) { try { ListPricesRequest pricesRequest = ListPricesRequest.builder() .tld(domainType) .build(); ListPricesIterable listRes = route53DomainsClient.listPricesPaginator(pricesRequest); listRes.stream() .flatMap(r -> r.prices().stream()) .forEach(content -> System.out.println(" Name: " + content.name() + " Registration: " + content.registrationPrice().price() + " " + content.registrationPrice().currency() + " Renewal: " + content.renewalPrice().price() + " " + content.renewalPrice().currency())); } catch (Route53Exception e) { System.err.println(e.getMessage()); System.exit(1); } } 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); } } public static void listOperations(Route53DomainsClient route53DomainsClient) { try { Date currentDate = new Date(); LocalDateTime localDateTime = currentDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); ZoneOffset zoneOffset = ZoneOffset.of("+01:00"); localDateTime = localDateTime.minusYears(1); Instant myTime = localDateTime.toInstant(zoneOffset); ListOperationsRequest operationsRequest = ListOperationsRequest.builder() .submittedSince(myTime) .build(); ListOperationsIterable listRes = route53DomainsClient.listOperationsPaginator(operationsRequest); listRes.stream() .flatMap(r -> r.operations().stream()) .forEach(content -> System.out.println(" Operation Id: " + content.operationId() + " Status: " + content.statusAsString() + " Date: " + content.submittedDate())); } catch (Route53Exception e) { System.err.println(e.getMessage()); System.exit(1); } } public static void listDomains(Route53DomainsClient route53DomainsClient) { try { ListDomainsIterable listRes = route53DomainsClient.listDomainsPaginator(); listRes.stream() .flatMap(r -> r.domains().stream()) .forEach(content -> System.out.println("The domain name is " + content.domainName())); } catch (Route53Exception e) { System.err.println(e.getMessage()); System.exit(1); } } }
-
Para obter detalhes da API, consulte os tópicos a seguir na Referência da API AWS SDK for Java 2.x.
-
- Kotlin
-
- SDK para Kotlin
-
nota
Há mais no GitHub. Encontre o exemplo completo e saiba como configurar e executar no Repositório de exemplos de código da 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}") } } }
-
Para obter detalhes da API, consulte os tópicos a seguir na Referência da API AWS SDK para Kotlin.
-
Para ver uma lista completa dos Guias do desenvolvedor de SDK da AWS e exemplos de código, consulte Usar o Route 53 com um AWS SDK. Este tópico também inclui informações sobre como começar e detalhes sobre versões anteriores do SDK.