Skip to content

Commit c578c83

Browse files
authored
Add useDualstackEndpoint configuration (#3957)
1 parent f2b5aaa commit c578c83

15 files changed

+5853
-85
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "feature",
3+
"category": "endpoint",
4+
"description": "Add useDualstackEndpoint configuration"
5+
}

lib/config-base.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,8 @@ export abstract class ConfigurationOptions {
271271
* Enables FIPS compatible endpoints.
272272
*/
273273
useFipsEndpoint?: boolean;
274+
/**
275+
* Enables IPv6 dualstack endpoint.
276+
*/
277+
useDualstackEndpoint?: boolean;
274278
}

lib/config.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ var PromisesDependency;
189189
*
190190
* @!attribute useFipsEndpoint
191191
* @return [Boolean] Enables FIPS compatible endpoints. Defaults to `false`.
192+
*
193+
* @!attribute useDualstackEndpoint
194+
* @return [Boolean] Enables IPv6 dualstack endpoint. Defaults to `false`.
192195
*/
193196
AWS.Config = AWS.util.inherit({
194197
/**
@@ -345,6 +348,8 @@ AWS.Config = AWS.util.inherit({
345348
* Defaults to 'legacy'.
346349
* @option options useFipsEndpoint [Boolean] Enables FIPS compatible endpoints.
347350
* Defaults to `false`.
351+
* @option options useDualstackEndpoint [Boolean] Enables IPv6 dualstack endpoint.
352+
* Defaults to `false`.
348353
*/
349354
constructor: function Config(options) {
350355
if (options === undefined) options = {};
@@ -569,7 +574,8 @@ AWS.Config = AWS.util.inherit({
569574
endpointCacheSize: 1000,
570575
hostPrefixEnabled: true,
571576
stsRegionalEndpoints: 'legacy',
572-
useFipsEndpoint: false
577+
useFipsEndpoint: false,
578+
useDualstackEndpoint: false
573579
},
574580

575581
/**

lib/config_use_dualstack.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import {ConfigBase} from './config-base';
2+
13
export interface UseDualstackConfigOptions {
24
/**
35
* Enables IPv6/IPv4 dualstack endpoint. When a DNS lookup is performed on an endpoint of this type, it returns an “A” record with an IPv4 address and an “AAAA” record with an IPv6 address.
46
* In most cases the network stack in the client environment will automatically prefer the AAAA record and make a connection using the IPv6 address.
57
* Note, however, that currently on Windows, the IPv4 address will be preferred.
8+
* @deprecated Use {@link ConfigBase.useDualstackEndpoint}
69
*/
710
useDualstack?: boolean;
811
}

lib/node_loader.js

+13
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ var USE_FIPS_ENDPOINT_CONFIG_OPTIONS = {
138138
default: false,
139139
};
140140

141+
var USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS = {
142+
environmentVariableSelector: function(env) {
143+
return getBooleanValue(env['AWS_USE_DUALSTACK_ENDPOINT']);
144+
},
145+
configFileSelector: function(profile) {
146+
return getBooleanValue(profile['use_dualstack_endpoint']);
147+
},
148+
default: false,
149+
};
150+
141151
// Update configuration keys
142152
AWS.util.update(AWS.Config.prototype.keys, {
143153
credentials: function () {
@@ -166,6 +176,9 @@ AWS.util.update(AWS.Config.prototype.keys, {
166176
return isFipsRegion(region)
167177
? true
168178
: util.loadConfig(USE_FIPS_ENDPOINT_CONFIG_OPTIONS);
179+
},
180+
useDualstackEndpoint: function() {
181+
return util.loadConfig(USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS);
169182
}
170183
});
171184

lib/region_config.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,25 @@ function applyConfig(service, config) {
3737
function configureEndpoint(service) {
3838
var keys = derivedKeys(service);
3939
var useFipsEndpoint = service.config.useFipsEndpoint;
40+
var useDualstackEndpoint = service.config.useDualstackEndpoint;
4041
for (var i = 0; i < keys.length; i++) {
4142
var key = keys[i];
4243
if (!key) continue;
4344

44-
var rules = useFipsEndpoint ? regionConfig.fipsRules : regionConfig.rules;
45+
var rules = useFipsEndpoint
46+
? useDualstackEndpoint
47+
? regionConfig.dualstackFipsRules
48+
: regionConfig.fipsRules
49+
: useDualstackEndpoint
50+
? regionConfig.dualstackRules
51+
: regionConfig.rules;
52+
4553
if (Object.prototype.hasOwnProperty.call(rules, key)) {
4654
var config = rules[key];
4755
if (typeof config === 'string') {
4856
config = regionConfig.patterns[config];
4957
}
5058

51-
// set dualstack endpoint
52-
if (service.config.useDualstack && util.isDualstackAvailable(service)) {
53-
config = util.copy(config);
54-
config.endpoint = config.endpoint.replace(
55-
/{service}\.({region}\.)?/,
56-
'{service}.dualstack.{region}.'
57-
);
58-
}
59-
6059
// set global endpoint
6160
service.isGlobalEndpoint = !!config.globalEndpoint;
6261
if (config.signingRegion) {

lib/region_config_data.json

+38
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,32 @@
120120
}
121121
},
122122

123+
"dualstackRules": {
124+
"*/*": {
125+
"endpoint": "{service}.{region}.api.aws"
126+
},
127+
"cn-*/*": {
128+
"endpoint": "{service}.{region}.api.amazonwebservices.com.cn"
129+
},
130+
"*/s3": "dualstackLegacy",
131+
"cn-*/s3": "dualstackLegacyCn",
132+
"*/s3-control": "dualstackLegacy",
133+
"cn-*/s3-control": "dualstackLegacyCn"
134+
},
135+
136+
"dualstackFipsRules": {
137+
"*/*": {
138+
"endpoint": "{service}-fips.{region}.api.aws"
139+
},
140+
"cn-*/*": {
141+
"endpoint": "{service}-fips.{region}.api.amazonwebservices.com.cn"
142+
},
143+
"*/s3": "dualstackFipsLegacy",
144+
"cn-*/s3": "dualstackFipsLegacyCn",
145+
"*/s3-control": "dualstackFipsLegacy",
146+
"cn-*/s3-control": "dualstackFipsLegacyCn"
147+
},
148+
123149
"patterns": {
124150
"globalSSL": {
125151
"endpoint": "https://{service}.amazonaws.com",
@@ -164,6 +190,18 @@
164190
},
165191
"fipsWithServiceOnly": {
166192
"endpoint": "{service}.{region}.amazonaws.com"
193+
},
194+
"dualstackLegacy": {
195+
"endpoint": "{service}.dualstack.{region}.amazonaws.com"
196+
},
197+
"dualstackLegacyCn": {
198+
"endpoint": "{service}.dualstack.{region}.amazonaws.com.cn"
199+
},
200+
"dualstackFipsLegacy": {
201+
"endpoint": "{service}-fips.dualstack.{region}.amazonaws.com"
202+
},
203+
"dualstackFipsLegacyCn": {
204+
"endpoint": "{service}-fips.dualstack.{region}.amazonaws.com.cn"
167205
}
168206
}
169207
}

lib/service.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,20 @@ AWS.Service = inherit({
2727
'Service must be constructed with `new\' operator');
2828
}
2929

30-
if (config && config.region) {
31-
var region = config.region;
32-
if (region_utils.isFipsRegion(region)) {
33-
config.region = region_utils.getRealRegion(region);
34-
config.useFipsEndpoint = true;
30+
if (config) {
31+
if (config.region) {
32+
var region = config.region;
33+
if (region_utils.isFipsRegion(region)) {
34+
config.region = region_utils.getRealRegion(region);
35+
config.useFipsEndpoint = true;
36+
}
37+
if (region_utils.isGlobalRegion(region)) {
38+
config.region = region_utils.getRealRegion(region);
39+
}
3540
}
36-
if (region_utils.isGlobalRegion(region)) {
37-
config.region = region_utils.getRealRegion(region);
41+
if (typeof config.useDualstack === 'boolean'
42+
&& typeof config.useDualstackEndpoint !== 'boolean') {
43+
config.useDualstackEndpoint = config.useDualstack;
3844
}
3945
}
4046

scripts/region-checker/allowlist.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ var allowlist = {
44
25,
55
85,
66
86,
7-
204,
8-
258,
9-
259
7+
207,
8+
261,
9+
262
1010
],
1111
'/credentials/cognito_identity_credentials.js': [
1212
78,

test/endpoint/index.spec.js

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ describe('endpoints', () => {
1313
clientName,
1414
region,
1515
useFipsEndpoint,
16+
useDualstackEndpoint,
1617
hostname,
1718
} of testCases) {
1819
it(`testing "${clientName}" with region: ${region}`, (done) => {
@@ -23,6 +24,7 @@ describe('endpoints', () => {
2324
const client = new AWS[clientName]({
2425
region,
2526
useFipsEndpoint,
27+
useDualstackEndpoint,
2628
hostPrefixEnabled: false
2729
});
2830

0 commit comments

Comments
 (0)