Skip to content

Commit

Permalink
chore(middleware-sdk-s3): remove deprecated regional endpoints middle…
Browse files Browse the repository at this point in the history
…ware (#3656)

* chore(middleware-sdk-s3): remove deprecated regional endpoints mw

* test(s3): add test for regional endpoints
  • Loading branch information
AllanZhengYP committed Jun 3, 2022
1 parent 312adb0 commit 346f139
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 123 deletions.
3 changes: 1 addition & 2 deletions clients/client-s3/src/S3Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
} from "@aws-sdk/middleware-host-header";
import { getLoggerPlugin } from "@aws-sdk/middleware-logger";
import { getRetryPlugin, resolveRetryConfig, RetryInputConfig, RetryResolvedConfig } from "@aws-sdk/middleware-retry";
import { getUseRegionalEndpointPlugin, getValidateBucketNamePlugin } from "@aws-sdk/middleware-sdk-s3";
import { getValidateBucketNamePlugin } from "@aws-sdk/middleware-sdk-s3";
import {
AwsAuthInputConfig,
AwsAuthResolvedConfig,
Expand Down Expand Up @@ -739,7 +739,6 @@ export class S3Client extends __Client<
this.middlewareStack.use(getLoggerPlugin(this.config));
this.middlewareStack.use(getAwsAuthPlugin(this.config));
this.middlewareStack.use(getValidateBucketNamePlugin(this.config));
this.middlewareStack.use(getUseRegionalEndpointPlugin(this.config));
this.middlewareStack.use(getAddExpectContinuePlugin(this.config));
this.middlewareStack.use(getUserAgentPlugin(this.config));
}
Expand Down
39 changes: 38 additions & 1 deletion clients/client-s3/test/S3.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="mocha" />
import { HttpRequest } from "@aws-sdk/protocol-http";
import { BuildMiddleware, SerializeMiddleware } from "@aws-sdk/types";
import { BuildMiddleware, FinalizeRequestMiddleware, SerializeMiddleware } from "@aws-sdk/types";
import chai from "chai";
import chaiAsPromised from "chai-as-promised";
import { PassThrough } from "stream";
Expand Down Expand Up @@ -171,3 +171,40 @@ describe("Throw 200 response", () => {
);
});
});

describe("regional endpoints", () => {
const endpointValidator: FinalizeRequestMiddleware<any, any> = (next, context) => (args) => {
// middleware intercept the request and return it early
const request = args.request as HttpRequest;
return Promise.resolve({
output: {
$metadata: { attempts: 0, httpStatusCode: 200 },
request,
context,
} as any,
response: {} as any,
});
};

it("should use regional endpoints if region is us-east-1", async () => {
const client = new S3({ region: "us-east-1" });
client.middlewareStack.add(endpointValidator, { step: "finalizeRequest", priority: "low" });
const result: any = await client.putObject({
Bucket: "bucket",
Key: "key",
Body: "body",
});
expect(result.request.hostname).to.eql("bucket.s3.us-east-1.amazonaws.com");
});

it("should use global endpoints if region is aws-global", async () => {
const client = new S3({ region: "aws-global" });
client.middlewareStack.add(endpointValidator, { step: "finalizeRequest", priority: "low" });
const result: any = await client.putObject({
Bucket: "bucket",
Key: "key",
Body: "body",
});
expect(result.request.hostname).to.eql("bucket.s3.amazonaws.com");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,6 @@ public List<RuntimeClientPlugin> getClientPlugins() {
HAS_MIDDLEWARE)
.operationPredicate((m, s, o) -> testServiceId(s) && o.getId().getName(s).equals("PutObject"))
.build(),
RuntimeClientPlugin.builder()
.withConventions(AwsDependency.S3_MIDDLEWARE.dependency, "UseRegionalEndpoint",
HAS_MIDDLEWARE)
.servicePredicate((m, s) -> testServiceId(s))
.build(),
RuntimeClientPlugin.builder()
.withConventions(AwsDependency.S3_MIDDLEWARE.dependency, "throw200Exceptions",
HAS_MIDDLEWARE)
Expand Down
1 change: 0 additions & 1 deletion packages/middleware-sdk-s3/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./check-content-length-header";
export * from "./throw-200-exceptions";
export * from "./use-regional-endpoint";
export * from "./validate-bucket-name";
62 changes: 0 additions & 62 deletions packages/middleware-sdk-s3/src/use-regional-endpoint.spec.ts

This file was deleted.

52 changes: 0 additions & 52 deletions packages/middleware-sdk-s3/src/use-regional-endpoint.ts

This file was deleted.

0 comments on commit 346f139

Please sign in to comment.