domains: migrate route53 to aws sdk v3

This commit is contained in:
Girish Ramakrishnan
2025-02-10 17:03:09 +01:00
parent ffc477091f
commit 58fcca58fc
3 changed files with 1282 additions and 20 deletions
+18 -20
View File
@@ -14,12 +14,13 @@ exports = module.exports = {
require('aws-sdk/lib/maintenance_mode_message').suppress = true;
const assert = require('assert'),
AWS = require('aws-sdk'),
BoxError = require('../boxerror.js'),
{ ConfiguredRetryStrategy } = require('@smithy/util-retry'),
constants = require('../constants.js'),
debug = require('debug')('box:dns/route53'),
dig = require('../dig.js'),
dns = require('../dns.js'),
{ Route53 } = require('@aws-sdk/client-route-53'),
safe = require('safetydance'),
waitForDns = require('./waitfordns.js'),
_ = require('underscore');
@@ -39,31 +40,28 @@ function getDnsCredentials(domainConfig) {
const credentials = {
accessKeyId: domainConfig.accessKeyId,
secretAccessKey: domainConfig.secretAccessKey,
region: domainConfig.region,
maxRetries: 20,
// route53 has a limit of 5 req/sec/region - https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/DNSLimitations.html#limits-api-requests
retryDelayOptions: {
customBackoff: (/* retryCount, error */) => 3000 // constant backoff - https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html#retryDelayOptions-property
},
};
if (domainConfig.endpoint) credentials.endpoint = new AWS.Endpoint(domainConfig.endpoint);
return credentials;
return {
region: domainConfig.region,
credentials,
retryStrategy: new ConfiguredRetryStrategy(20 /* max attempts */, (/* attempt */) => 3000 /* constant backoff */)
};
}
async function getZoneByName(domainConfig, zoneName) {
assert.strictEqual(typeof domainConfig, 'object');
assert.strictEqual(typeof zoneName, 'string');
const route53 = new AWS.Route53(getDnsCredentials(domainConfig));
const route53 = new Route53(getDnsCredentials(domainConfig));
// backward compat for 2.2, where we only required access to "listHostedZones"
let listHostedZones;
if (domainConfig.listHostedZonesByName) {
listHostedZones = route53.listHostedZonesByName({ MaxItems: '1', DNSName: zoneName + '.' }).promise();
listHostedZones = route53.listHostedZonesByName({ MaxItems: '1', DNSName: zoneName + '.' });
} else {
listHostedZones = route53.listHostedZones({}).promise(); // currently, this route does not support > 100 zones
listHostedZones = route53.listHostedZones({}); // currently, this route does not support > 100 zones
}
const [error, result] = await safe(listHostedZones);
@@ -86,8 +84,8 @@ async function getHostedZone(domainConfig, zoneName) {
const zone = await getZoneByName(domainConfig, zoneName);
const route53 = new AWS.Route53(getDnsCredentials(domainConfig));
const [error, result] = await safe(route53.getHostedZone({ Id: zone.Id }).promise());
const route53 = new Route53(getDnsCredentials(domainConfig));
const [error, result] = await safe(route53.getHostedZone({ Id: zone.Id }));
if (error && error.code === 'AccessDenied') throw new BoxError(BoxError.ACCESS_DENIED, error.message);
if (error && error.code === 'InvalidClientTokenId') throw new BoxError(BoxError.ACCESS_DENIED, error.message);
if (error) throw new BoxError(BoxError.EXTERNAL_ERROR, error.message);
@@ -126,8 +124,8 @@ async function upsert(domainObject, location, type, values) {
HostedZoneId: zone.Id
};
const route53 = new AWS.Route53(getDnsCredentials(domainConfig));
const [error] = await safe(route53.changeResourceRecordSets(params).promise());
const route53 = new Route53(getDnsCredentials(domainConfig));
const [error] = await safe(route53.changeResourceRecordSets(params));
if (error && error.code === 'AccessDenied') throw new BoxError(BoxError.ACCESS_DENIED, error.message);
if (error && error.code === 'InvalidClientTokenId') throw new BoxError(BoxError.ACCESS_DENIED, error.message);
if (error && error.code === 'PriorRequestNotComplete') throw new BoxError(BoxError.BUSY, error.message);
@@ -153,8 +151,8 @@ async function get(domainObject, location, type) {
StartRecordType: type
};
const route53 = new AWS.Route53(getDnsCredentials(domainConfig));
const [error, result] = await safe(route53.listResourceRecordSets(params).promise());
const route53 = new Route53(getDnsCredentials(domainConfig));
const [error, result] = await safe(route53.listResourceRecordSets(params));
if (error && error.code === 'AccessDenied') throw new BoxError(BoxError.ACCESS_DENIED, error.message);
if (error && error.code === 'InvalidClientTokenId') throw new BoxError(BoxError.ACCESS_DENIED, error.message);
if (error) throw new BoxError(BoxError.EXTERNAL_ERROR, error.message);
@@ -196,8 +194,8 @@ async function del(domainObject, location, type, values) {
HostedZoneId: zone.Id
};
const route53 = new AWS.Route53(getDnsCredentials(domainConfig));
const [error] = await safe(route53.changeResourceRecordSets(params).promise());
const route53 = new Route53(getDnsCredentials(domainConfig));
const [error] = await safe(route53.changeResourceRecordSets(params));
if (error && error.code === 'AccessDenied') throw new BoxError(BoxError.ACCESS_DENIED, error.message);
if (error && error.code === 'InvalidClientTokenId') throw new BoxError(BoxError.ACCESS_DENIED, error.message);
if (error && error.message && error.message.indexOf('it was not found') !== -1) {