{"id":232,"date":"2025-02-22T00:30:30","date_gmt":"2025-02-22T00:30:30","guid":{"rendered":"https:\/\/lmponceb.com\/?p=232"},"modified":"2025-02-22T00:30:30","modified_gmt":"2025-02-22T00:30:30","slug":"utilitario-para-migracion-de-una-zona-de-route53","status":"publish","type":"post","link":"https:\/\/lmponceb.com\/index.php\/2025\/02\/22\/utilitario-para-migracion-de-una-zona-de-route53\/","title":{"rendered":"Utilitario para Migraci\u00f3n de una zona de route53"},"content":{"rendered":"\n<p>Utilitario para la conversi\u00f3n de la respuesta de list-resource-record-sets a un formato v\u00e1lido para change-resource-record-sets, para la migraci\u00f3n de una zona de route53 de una cuenta a otra dentro de AWS<\/p>\n\n\n\n<p>En base a la documentaci\u00f3n de AWS: <a href=\"https:\/\/docs.aws.amazon.com\/Route53\/latest\/DeveloperGuide\/hosted-zones-migrating.html\">AWS: Migrating a hosted zone to a different AWS account<\/a><\/p>\n\n\n\n<style>\n    body {\n      font-family: Arial, sans-serif;\n      margin: 20px;\n    }\n    textarea {\n      width: 100%;\n      height: 200px;\n      font-family: monospace;\n      margin-bottom: 10px;\n    }\n    button {\n      padding: 10px 20px;\n      font-size: 16px;\n      margin-bottom: 20px;\n    }\n    table {\n      width: 100%;\n      border-collapse: collapse;\n      margin-top: 20px;\n    }\n    table, th, td {\n      border: 1px solid #ccc;\n    }\n    th, td {\n      padding: 8px;\n      text-align: left;\n    }\n    th {\n      background-color: #f2f2f2;\n    }\n  <\/style>\n  <p>Pega el resultado de <strong>aws route53 list-resource-record-sets &#8211;hosted-zone-id XXXXXXXXXXXX<\/strong> aqu\u00ed:<\/p>\n\n  <textarea id=\"inputArea\" placeholder=\"Contenido de list-resource-record-sets\"><\/textarea>\n  <br>\n  <button onclick=\"processTraffic()\">Convertir<\/button>\n  \n  <h2>Resultado<\/h2>\n  <textarea id=\"outputArea\" placeholder=\"Resultado de transformar\"><\/textarea>\n  \n  <h2>Tabla de Registros<\/h2>\n  <table id=\"resultTable\">\n    <thead>\n      <tr>\n        <th>Name<\/th>\n        <th>Type<\/th>\n        <th>TTL<\/th>\n        <th>ResourceRecords<\/th>\n      <\/tr>\n    <\/thead>\n    <tbody>\n      <!-- Table rows will be inserted here -->\n    <\/tbody>\n  <\/table>\n\n  <script>\n    function processTraffic() {\n      const inputText = document.getElementById('inputArea').value;\n      let data;\n      try {\n        data = JSON.parse(inputText);\n      } catch (error) {\n        document.getElementById('outputArea').value = \"Error: Invalid JSON input. \" + error;\n        return;\n      }\n      \n      if (!data.ResourceRecordSets || !Array.isArray(data.ResourceRecordSets)) {\n        document.getElementById('outputArea').value = \"Error: JSON does not contain a valid 'ResourceRecordSets' array.\";\n        return;\n      }\n      \n      \/\/ Filter out records with Type \"NS\" or \"SOA\"\n      const filteredRecords = data.ResourceRecordSets.filter(record => {\n        return record.Type !== \"NS\" && record.Type !== \"SOA\";\n      });\n      \n      \/\/ Transform each record into a change entry with an Action property and embed the record inside ResourceRecordSet (singular)\n      const changes = filteredRecords.map(record => {\n        return {\n          \"Action\": \"CREATE\",\n          \"ResourceRecordSet\": record\n        };\n      });\n      \n      \/\/ Build the transformed JSON object\n      const transformedJSON = {\n        \"Comment\": \"string\",\n        \"Changes\": changes\n      };\n      \n      \/\/ Output the transformed JSON in the second textarea (pretty-printed)\n      document.getElementById('outputArea').value = JSON.stringify(transformedJSON, null, 4);\n      \n      \/\/ Build the table from the filtered records\n      const tbody = document.getElementById('resultTable').getElementsByTagName('tbody')[0];\n      tbody.innerHTML = \"\";\n      \n      filteredRecords.forEach(record => {\n        const row = document.createElement('tr');\n        \n        \/\/ Name cell\n        const nameCell = document.createElement('td');\n        nameCell.textContent = record.Name || \"\";\n        row.appendChild(nameCell);\n        \n        \/\/ Type cell\n        const typeCell = document.createElement('td');\n        typeCell.textContent = record.Type || \"\";\n        row.appendChild(typeCell);\n        \n        \/\/ TTL cell (handles cases where TTL might be undefined)\n        const ttlCell = document.createElement('td');\n        ttlCell.textContent = record.TTL !== undefined ? record.TTL : \"\";\n        row.appendChild(ttlCell);\n        \n        \/\/ ResourceRecords cell (displaying each Value separated by a <br>)\n        const rrCell = document.createElement('td');\n        let rrContent = \"\";\n        if (record.ResourceRecords && Array.isArray(record.ResourceRecords)) {\n          rrContent = record.ResourceRecords.map(rr => rr.Value).join(\"<br>\");\n        } else if (record.AliasTarget) {\n          rrContent = \"Alias: \" + (record.AliasTarget.DNSName || JSON.stringify(record.AliasTarget));\n        }\n        rrCell.innerHTML = rrContent;\n        row.appendChild(rrCell);\n        \n        tbody.appendChild(row);\n      });\n    }\n  <\/script>\n","protected":false},"excerpt":{"rendered":"<p>Utilitario para la conversi\u00f3n de la respuesta de list-resource-record-sets a un formato v\u00e1lido para change-resource-record-sets, para la migraci\u00f3n de una zona de route53 de una cuenta a otra dentro de AWS En base a la documentaci\u00f3n de AWS: AWS: Migrating a hosted zone to a different AWS account Pega el resultado de aws route53 list-resource-record-sets &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/lmponceb.com\/index.php\/2025\/02\/22\/utilitario-para-migracion-de-una-zona-de-route53\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Utilitario para Migraci\u00f3n de una zona de route53&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-232","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/lmponceb.com\/index.php\/wp-json\/wp\/v2\/posts\/232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lmponceb.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lmponceb.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lmponceb.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lmponceb.com\/index.php\/wp-json\/wp\/v2\/comments?post=232"}],"version-history":[{"count":1,"href":"https:\/\/lmponceb.com\/index.php\/wp-json\/wp\/v2\/posts\/232\/revisions"}],"predecessor-version":[{"id":233,"href":"https:\/\/lmponceb.com\/index.php\/wp-json\/wp\/v2\/posts\/232\/revisions\/233"}],"wp:attachment":[{"href":"https:\/\/lmponceb.com\/index.php\/wp-json\/wp\/v2\/media?parent=232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lmponceb.com\/index.php\/wp-json\/wp\/v2\/categories?post=232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lmponceb.com\/index.php\/wp-json\/wp\/v2\/tags?post=232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}