Transfer DNS management from LightSail to Route53

0

I inherited a system that uses LightSail for DNS and even though the underpinnings are Route53, I'd like to transfer the zone/DNS to Route53. Is there a way to export a zone file, etc. to do the transfer?

asked 6 months ago276 views
2 Answers
0

Hello.

As far as I know, I don't think there is a way to retrieve the zone file and reconfigure it to Route53.
Therefore, if you want to move your domain to Route53, you will need to copy the record settings one by one.

profile picture
EXPERT
answered 6 months ago
0

You use this script to generate a zone file, copy the contents and use the "Import zone file" feature.

#!/bin/bash

# Variables
DOMAIN="[Enter your Domain name]"
HOSTED_ZONE_FILE="${DOMAIN}.zone"

# Fetch DNS records from Lightsail
RECORDS=$(aws lightsail --region us-east-1 get-domain --domain-name $DOMAIN --query 'domain.domainEntries' --output json)

# Check if we got a valid response with records
if [[ -z "$RECORDS" ]]; then
  echo "No records found for domain $DOMAIN or error fetching records."
  exit 1
fi

# Start creating the zone file 
cat > $HOSTED_ZONE_FILE <<EOF
\$TTL 86400
;
EOF

# Process each record and append to the zone file
echo "${RECORDS}" | jq -c '.[]' | while read -r row; do
    TYPE=$(echo $row | jq -r '.type')
    NAME=$(echo $row | jq -r '.name')
    VALUE=$(echo $row | jq -r '.target')

    # Skip if record type is not recognized or it's an SOA or NS record (already handled)
    if [[ "$TYPE" == "SOA" || "$TYPE" == "NS" ]]; then
        continue
    fi

    # Append record to zone file based on type
    case $TYPE in
        A)
            echo "$NAME IN A $VALUE" >> $HOSTED_ZONE_FILE
            ;;
        CNAME)
            echo "$NAME IN CNAME $VALUE" >> $HOSTED_ZONE_FILE
            ;;
        MX)
            echo "$NAME IN MX $VALUE" >> $HOSTED_ZONE_FILE
            ;;
        TXT)
            echo "$NAME IN TXT $VALUE" >> $HOSTED_ZONE_FILE
            ;;
        *)
            echo "Unsupported record type: $TYPE" >&2
            ;;
    esac
done

echo "Zone file created: $HOSTED_ZONE_FILE"
answered 5 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions