Skip to content

Commit 3aca84f

Browse files
Chase Coalwelltrivikr
Chase Coalwell
authored andcommitted
fix: resolve region (#560)
* fix: resolve region
1 parent 9a9a601 commit 3aca84f

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Diff for: packages/middleware-location-constraint/src/index.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe("locationConstrainMiddleware", () => {
99

1010
it("should remove any CreateBucketConfiguration from requests directed at us-east-1", async () => {
1111
const handler = locationConstraintMiddleware({
12-
region: "us-east-1"
12+
region: () => Promise.resolve("us-east-1")
1313
})(next, {} as any);
1414
const input = {
1515
CreateBucketConfiguration: { LocationConstraint: "us-east-1" },
@@ -28,7 +28,7 @@ describe("locationConstrainMiddleware", () => {
2828

2929
it("should apply a CreateBucketConfiguration with a LocationConstraint of the target region for requests directed outside of us-east-1", async () => {
3030
const handler = locationConstraintMiddleware({
31-
region: "us-east-2"
31+
region: () => Promise.resolve("us-east-2")
3232
})(next, {} as any);
3333
const input = {
3434
foo: "bar"
@@ -47,7 +47,7 @@ describe("locationConstrainMiddleware", () => {
4747

4848
it("should do nothing if a LocationConstraint had already been set on a request directed outside of us-east-1", async () => {
4949
const handler = locationConstraintMiddleware({
50-
region: "us-east-2"
50+
region: () => Promise.resolve("us-east-2")
5151
})(next, {} as any);
5252
const input = {
5353
CreateBucketConfiguration: { LocationConstraint: "us-east-1" },

Diff for: packages/middleware-location-constraint/src/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export function locationConstraintMiddleware(
2424
args: InitializeHandlerArguments<any>
2525
): Promise<InitializeHandlerOutput<Output>> => {
2626
const { CreateBucketConfiguration } = args.input;
27+
//After region config resolution, region is a Provider<string>
28+
const region = await options.region();
2729
if (
2830
!CreateBucketConfiguration ||
2931
!CreateBucketConfiguration.LocationConstraint
@@ -32,10 +34,10 @@ export function locationConstraintMiddleware(
3234
...args,
3335
input: {
3436
...args.input,
35-
CreateBucketConfiguration: { LocationConstraint: options.region }
37+
CreateBucketConfiguration: { LocationConstraint: region }
3638
}
3739
};
38-
} else if (options.region === "us-east-1") {
40+
} else if (region === "us-east-1") {
3941
args = {
4042
...args,
4143
input: {

0 commit comments

Comments
 (0)