Skip to content

Commit d7aa2c3

Browse files
authored
fix(middleware-bucket-endpoint): remove dualstack from hostname before processing (#3003)
1 parent f2fb280 commit d7aa2c3

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

packages/middleware-bucket-endpoint/src/bucketHostname.spec.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ describe("bucketHostname", () => {
66
const region = "us-west-2";
77
describe("from bucket name", () => {
88
[
9+
{ baseHostname: "s3.dualstack.us-west-2.amazonaws.com", isCustomEndpoint: false, dualstackEndpoint: true },
910
{ baseHostname: "s3.us-west-2.amazonaws.com", isCustomEndpoint: false },
1011
{ baseHostname: "beta.example.com", isCustomEndpoint: true },
1112
].forEach(({ baseHostname, isCustomEndpoint }) => {
@@ -187,20 +188,24 @@ describe("bucketHostname", () => {
187188

188189
describe("from Access Point ARN", () => {
189190
describe("populates access point endpoint from ARN", () => {
190-
const s3Hostname = "s3.us-west-2.amazonaws.com";
191191
const customHostname = "example.com";
192192

193-
describe(`baseHostname: ${s3Hostname}`, () => {
194-
const baseHostname = s3Hostname;
193+
describe.each([
194+
["s3.us-west-2.amazonaws.com", false],
195+
["s3.dualstack.us-west-2.amazonaws.com", true],
196+
])(`baseHostname: %s, dualstackEndpoint: %s`, (baseHostname, dualstackEndpoint) => {
195197
it("should use client region", () => {
196198
const { bucketEndpoint, hostname } = bucketHostname({
197199
bucketName: parseArn("arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint"),
198200
baseHostname,
199201
isCustomEndpoint: false,
200202
clientRegion: region,
203+
dualstackEndpoint,
201204
});
202205
expect(bucketEndpoint).toBe(true);
203-
expect(hostname).toBe("myendpoint-123456789012.s3-accesspoint.us-west-2.amazonaws.com");
206+
expect(hostname).toBe(
207+
`myendpoint-123456789012.s3-accesspoint${dualstackEndpoint ? ".dualstack" : ""}.us-west-2.amazonaws.com`
208+
);
204209
});
205210

206211
it("should use ARN region", () => {
@@ -210,9 +215,12 @@ describe("bucketHostname", () => {
210215
isCustomEndpoint: false,
211216
clientRegion: region,
212217
useArnRegion: true,
218+
dualstackEndpoint,
213219
});
214220
expect(bucketEndpoint).toBe(true);
215-
expect(hostname).toBe("myendpoint-123456789012.s3-accesspoint.us-east-1.amazonaws.com");
221+
expect(hostname).toBe(
222+
`myendpoint-123456789012.s3-accesspoint${dualstackEndpoint ? ".dualstack" : ""}.us-east-1.amazonaws.com`
223+
);
216224
});
217225
});
218226

packages/middleware-bucket-endpoint/src/bucketHostname.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,16 @@ export interface BucketHostname {
3333

3434
export const bucketHostname = (options: BucketHostnameParams | ArnHostnameParams): BucketHostname => {
3535
validateCustomEndpoint(options);
36+
37+
// TODO: Remove checks for ".dualstack" from entire middleware.
38+
const { dualstackEndpoint, baseHostname } = options;
39+
const updatedBaseHostname = dualstackEndpoint ? baseHostname.replace(".dualstack", "") : baseHostname;
40+
3641
return isBucketNameOptions(options)
3742
? // Construct endpoint when bucketName is a string referring to a bucket name
38-
getEndpointFromBucketName(options)
43+
getEndpointFromBucketName({ ...options, baseHostname: updatedBaseHostname })
3944
: // Construct endpoint when bucketName is an ARN referring to an S3 resource like Access Point
40-
getEndpointFromArn(options);
45+
getEndpointFromArn({ ...options, baseHostname: updatedBaseHostname });
4146
};
4247

4348
const getEndpointFromBucketName = ({

0 commit comments

Comments
 (0)