Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions packages/middleware-location-constraint/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@ export function locationConstraintMiddleware(
//After region config resolution, region is a Provider<string>
const region = await options.region();
if (!CreateBucketConfiguration?.LocationConstraint && !CreateBucketConfiguration?.Location) {
args = {
...args,
input: {
...args.input,
CreateBucketConfiguration: region === "us-east-1" ? undefined : { LocationConstraint: region },
},
};
if (region !== "us-east-1") {
args.input.CreateBucketConfiguration = args.input.CreateBucketConfiguration ?? {};
args.input.CreateBucketConfiguration.LocationConstraint = region;
}
}

return next(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,32 @@ describe("middleware-location-constraint", () => {
expect.hasAssertions();
});

it("should populate other elements of the CreateBucketConfiguration regardless of Location or LocationConstraint", async () => {
const client = new S3({ region: "us-east-1" });

requireRequestsFrom(client).toMatch({
body(body = "") {
expect(body).toContain(
`<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Tags><Tag><Key>my-tag-key</Key><Value>my-tag-value</Value></Tag></Tags></CreateBucketConfiguration>`
);
},
});

await client.createBucket({
Bucket: "b",
CreateBucketConfiguration: {
Tags: [
{
Key: "my-tag-key",
Value: "my-tag-value",
},
],
},
});

expect.hasAssertions();
});

it("also not for S3 Express buckets", async () => {
const client = new S3({ region: "us-west-2" });

Expand Down
Loading