How To Check And Register A Domain Name Programmatically Using API?
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
Though domain names are not an ephemeral entity and generally the domain registration is done manually using some sort of UI provided by domain registerer. But there may be a use case where you want to check domain name availability or register a new domain using API. If that is the case then you are in the right place. Today I will cover how to check and register a new domain name programmatically using AWS Route53 service and AWS CLI.
AWS Route53 service provides API endpoints to check a domain name availability and if the domain name is available, you can also register the domain name using the same API end point programmatically. To check and register a new domain name, you need to have an active AWS account and proper access to the account.
How To Check And Register A Domain Name Programmatically Using API?
Prerequisites:
AWS CLI installed and configured with proper access.
You can use below link to install and configure AWS CLI.
https://cloudaffaire.com/how-to-install-aws-cli/
https://cloudaffaire.com/how-to-configure-aws-cli/
Step 1: Check if a domain name is available for registration.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
## Check if a domain name is available to regsiter aws route53domains check-domain-availability \ --region us-east-1 \ --domain-name cloudaffaire.com ## If output is "UNAVAILABLE", that means you can't register this domain ## { ## "Availability": "UNAVAILABLE" ## } aws route53domains check-domain-availability \ --region us-east-1 \ --domain-name omegaskill.com ## If output is "AVAILABLE", that means you can register this domain ## { ## "Availability": "AVAILABLE" ## } |
Step 2: Register a new domain with AWS Route53
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
## Register a new domain with Route53 ## Create a json file with domain registration details ## Replace the value as per your requirements ## Get the required value from below link ## https://docs.aws.amazon.com/cli/latest/reference/route53domains/register-domain.html cat <<'EOF' > domain_registration_details.json { "DomainName": "omegaskill.com", "DurationInYears": 1, "AutoRenew": true, "AdminContact": { "FirstName": "Debjeet", "LastName": "Bhowmik", "ContactType": "PERSON", "AddressLine1": "Belghoria", "City": "Kolkata", "State": "WB", "CountryCode": "IN", "ZipCode": "700056", "PhoneNumber": "+91.8017702999", "Email": "contact@cloudaffaire.com" }, "RegistrantContact": { "FirstName": "Debjeet", "LastName": "Bhowmik", "ContactType": "PERSON", "AddressLine1": "Belghoria", "City": "Kolkata", "State": "WB", "CountryCode": "IN", "ZipCode": "700056", "PhoneNumber": "+91.8017702999", "Email": "contact@cloudaffaire.com" }, "TechContact": { "FirstName": "Debjeet", "LastName": "Bhowmik", "ContactType": "PERSON", "AddressLine1": "Belghoria", "City": "Kolkata", "State": "WB", "CountryCode": "IN", "ZipCode": "700056", "PhoneNumber": "+91.8017702999", "Email": "contact@cloudaffaire.com" }, "PrivacyProtectAdminContact": true, "PrivacyProtectRegistrantContact": true, "PrivacyProtectTechContact": true } EOF ## Register the new domain OP_ID=$(aws route53domains register-domain \ --region us-east-1 \ --cli-input-json file://domain_registration_details.json | jq -r .OperationId ) |
Warning: There is a cost associated with domain name registration and the amount depends on the TLD (.com will cost you around 12$ + tax).
Note: Replace the details provided for domain registration according to your requirement.
Once you have registered a new domain, there may be additional steps you need to perform before the domain is activated and is ready to use. In case of some domain names, you may need to validated your contact details first. In case of India, you also need to pay the amount in advance before your domain is activated.
Step 3: Check the status of your domain registration
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
## Get the status of domain registration request aws route53domains get-operation-detail \ --region us-east-1 \ --operation-id $OP_ID ## Check contact validation status aws route53domains get-contact-reachability-status \ --region us-east-1 \ --domain-name omegaskill.com ## Some TLD may require email validation ## validate your email address if required by clicking on the link ## on the email sent by AWS for the same. ## Check the billing details for your domain aws route53domains view-billing \ --region us-east-1 \ --start-time 'September 14, 2020, 12:00:00' \ --end-time 'September 14, 2021, 12:00:00' \ --max-items 2 ## If you domain registration address is India, ## you need to pay the bill 1st before the domain is activated |
Step 4: Get your domain details
1 2 3 4 5 6 7 8 9 10 11 12 13 |
## Get details for your domain aws route53domains get-domain-detail \ --region us-east-1 \ --domain-name omegaskill.com ## Get details on the hosted zone HOSTED_ZONE_ID=$(aws route53 list-hosted-zones | jq -r .HostedZones[0].Id) && aws route53 get-hosted-zone \ --id $HOSTED_ZONE_ID ## Get the details on DNS records created by default aws route53 list-resource-record-sets \ --hosted-zone-id $HOSTED_ZONE_ID |
Note: Hosted zone is where you manage your DNS records in AWS Route53.
Hope you have enjoyed this article. To know more about AWS Route53, please refer below official documentation
https://docs.aws.amazon.com/route53/index.html