From 3f16611cf0f0f4c4e971e0a4808d8e2359c8d94c Mon Sep 17 00:00:00 2001 From: Yuri Slobodyanyuk Date: Mon, 23 Jan 2023 10:25:12 +0000 Subject: [PATCH] Added AWS CLI Route53 cheat sheet --- cheat-sheets/Route53-AWS-CLI-examples.adoc | 144 +++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 cheat-sheets/Route53-AWS-CLI-examples.adoc diff --git a/cheat-sheets/Route53-AWS-CLI-examples.adoc b/cheat-sheets/Route53-AWS-CLI-examples.adoc new file mode 100644 index 0000000..4bfd395 --- /dev/null +++ b/cheat-sheets/Route53-AWS-CLI-examples.adoc @@ -0,0 +1,144 @@ += Route53 AWS CLI examples cookbook +:homepage: https://yurisk.info +:toc: +Author: Yuri Slobodyanyuk, https://www.linkedin.com/in/yurislobodyanyuk/ + + +== Short Introduction +* AWS ROute53 is the only service with 100% SLA. +* Amazon Registrar does domain registration only for _.com, .org, .net_ domains, the + rest are registered via _Gandi SAS_ + + + +== List all hosted zones (private and public) +[source, bash] +---- +aws route53 list-hosted-zones +---- + +If you are using configuration profiles: + +[source, bash] +---- +aws route53 list-hosted-zones --profile +---- + +This command returns _zone-id_ you will need in future queries. + +== Show all records of a zone + +[source, bash] +---- +aws route53 list-resource-record-sets --hosted-zone-id Z3HR6JS50CWURT --profile +awsadmin +---- + + +=== Filter output for specific records +Show all and only A records from a zone: + +---- +aws route53 list-resource-record-sets --hosted-zone-id ZN36CWKHEDURT --profile +awsadmin --query "ResourceRecordSets[?Type == 'A'] " +---- + +Show only records matching the given record value (_here _www.yurisk.info_): + +---- +aws route53 list-resource-record-sets --hosted-zone-id ZN36CWKHEDURT --profile +awsadmin --query "ResourceRecordSets[?Name == 'www.yurisk.info.'] " +---- + +NOTE: AWS returns maximum 100 items in one response. Use paging with `NextToen` +if you expect to get more results. + +== Create a new public zone + +Create a new public zone named _example334455.com_: + +---- +aws route53 create-hosted-zone --name example334455.com --caller-reference +some-text-for-me-for-reference +---- + +On success returns zone's ID, request status (e.g. `Pending`), allocated name +servers. The `caller-reference` you set is used for identifying this request in +logs etc. and can be arbitrary string. + +== Add A record to a zone +While mainly expected to store the A record in JSON format in a local file, we +can specify the record(s) to add explicitly with `--change-batch`. Let's add A +record _www.example334455.com_ wtih TTL of 600, pointing to IP _1.2.3.4_: + +---- +aws route53 change-resource-record-sets --hosted-zone-id Z0967968IADGHN5TI3WW +--change-batch ' +{ +"Comment": "Adding A record", +"Changes": [ +{ +"Action": "CREATE", +"ResourceRecordSet": { +"Name": "www.example334455.com", +"Type": "A", +"TTL": 600, +"ResourceRecords": [ +{ +"Value": "1.2.3.4" +} +] +} +} +] +} +' +---- + +== Delete a record from a zone +Let's delete the A record just created _www.example334455.com_ (we use +`Action:DELETE`): + +---- +aws route53 change-resource-record-sets --hosted-zone-id Z0967968IADGHN5TI3WW +--change-batch ' +{ +"Comment": "Adding A record", +"Changes": [ +{ +"Action": "DELETE", +"ResourceRecordSet": { +"Name": "www.example334455.com", +"Type": "A", +"TTL": 600, +"ResourceRecords": [ +{ +"Value": "1.2.3.4" +} +] +} +} +] +} +' +---- + +== Delete a zone completely +NOTE: You cannot delete a non-empty zone, have to 1st delete all records except +NS. + +Trying to delete a zone with other than NS records gives this error: + +---- +An error occurred (HostedZoneNotEmpty) when calling the DeleteHostedZone +operation: The specified hosted zone contains non-required resource record +sets and so cannot be deleted +---- + +We delete the empty zone _example334455.com_: + +---- +aws route53 delete-hosted-zone --id Z0967968IADGHN5TI3WW +---- + +