Skip to content

Commit 346f139

Browse files
authored
chore(middleware-sdk-s3): remove deprecated regional endpoints middleware (#3656)
* chore(middleware-sdk-s3): remove deprecated regional endpoints mw * test(s3): add test for regional endpoints
1 parent 312adb0 commit 346f139

File tree

6 files changed

+39
-123
lines changed

6 files changed

+39
-123
lines changed

clients/client-s3/src/S3Client.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
} from "@aws-sdk/middleware-host-header";
2828
import { getLoggerPlugin } from "@aws-sdk/middleware-logger";
2929
import { getRetryPlugin, resolveRetryConfig, RetryInputConfig, RetryResolvedConfig } from "@aws-sdk/middleware-retry";
30-
import { getUseRegionalEndpointPlugin, getValidateBucketNamePlugin } from "@aws-sdk/middleware-sdk-s3";
30+
import { getValidateBucketNamePlugin } from "@aws-sdk/middleware-sdk-s3";
3131
import {
3232
AwsAuthInputConfig,
3333
AwsAuthResolvedConfig,
@@ -739,7 +739,6 @@ export class S3Client extends __Client<
739739
this.middlewareStack.use(getLoggerPlugin(this.config));
740740
this.middlewareStack.use(getAwsAuthPlugin(this.config));
741741
this.middlewareStack.use(getValidateBucketNamePlugin(this.config));
742-
this.middlewareStack.use(getUseRegionalEndpointPlugin(this.config));
743742
this.middlewareStack.use(getAddExpectContinuePlugin(this.config));
744743
this.middlewareStack.use(getUserAgentPlugin(this.config));
745744
}

clients/client-s3/test/S3.spec.ts

+38-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="mocha" />
22
import { HttpRequest } from "@aws-sdk/protocol-http";
3-
import { BuildMiddleware, SerializeMiddleware } from "@aws-sdk/types";
3+
import { BuildMiddleware, FinalizeRequestMiddleware, SerializeMiddleware } from "@aws-sdk/types";
44
import chai from "chai";
55
import chaiAsPromised from "chai-as-promised";
66
import { PassThrough } from "stream";
@@ -171,3 +171,40 @@ describe("Throw 200 response", () => {
171171
);
172172
});
173173
});
174+
175+
describe("regional endpoints", () => {
176+
const endpointValidator: FinalizeRequestMiddleware<any, any> = (next, context) => (args) => {
177+
// middleware intercept the request and return it early
178+
const request = args.request as HttpRequest;
179+
return Promise.resolve({
180+
output: {
181+
$metadata: { attempts: 0, httpStatusCode: 200 },
182+
request,
183+
context,
184+
} as any,
185+
response: {} as any,
186+
});
187+
};
188+
189+
it("should use regional endpoints if region is us-east-1", async () => {
190+
const client = new S3({ region: "us-east-1" });
191+
client.middlewareStack.add(endpointValidator, { step: "finalizeRequest", priority: "low" });
192+
const result: any = await client.putObject({
193+
Bucket: "bucket",
194+
Key: "key",
195+
Body: "body",
196+
});
197+
expect(result.request.hostname).to.eql("bucket.s3.us-east-1.amazonaws.com");
198+
});
199+
200+
it("should use global endpoints if region is aws-global", async () => {
201+
const client = new S3({ region: "aws-global" });
202+
client.middlewareStack.add(endpointValidator, { step: "finalizeRequest", priority: "low" });
203+
const result: any = await client.putObject({
204+
Bucket: "bucket",
205+
Key: "key",
206+
Body: "body",
207+
});
208+
expect(result.request.hostname).to.eql("bucket.s3.amazonaws.com");
209+
});
210+
});

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddS3Config.java

-5
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,6 @@ public List<RuntimeClientPlugin> getClientPlugins() {
165165
HAS_MIDDLEWARE)
166166
.operationPredicate((m, s, o) -> testServiceId(s) && o.getId().getName(s).equals("PutObject"))
167167
.build(),
168-
RuntimeClientPlugin.builder()
169-
.withConventions(AwsDependency.S3_MIDDLEWARE.dependency, "UseRegionalEndpoint",
170-
HAS_MIDDLEWARE)
171-
.servicePredicate((m, s) -> testServiceId(s))
172-
.build(),
173168
RuntimeClientPlugin.builder()
174169
.withConventions(AwsDependency.S3_MIDDLEWARE.dependency, "throw200Exceptions",
175170
HAS_MIDDLEWARE)
-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
export * from "./check-content-length-header";
22
export * from "./throw-200-exceptions";
3-
export * from "./use-regional-endpoint";
43
export * from "./validate-bucket-name";

packages/middleware-sdk-s3/src/use-regional-endpoint.spec.ts

-62
This file was deleted.

packages/middleware-sdk-s3/src/use-regional-endpoint.ts

-52
This file was deleted.

0 commit comments

Comments
 (0)