Skip to content

Commit 600e725

Browse files
ekjotmultaniNika Hassani
authored andcommitted
updated resource.ts and backend.ts for multiple buckets in our infra-gen2 stack
1 parent 9246fff commit 600e725

File tree

1 file changed

+30
-4
lines changed
  • infra-gen2/backends/storage/main/amplify

1 file changed

+30
-4
lines changed

infra-gen2/backends/storage/main/amplify/backend.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,52 @@
11
import { defineBackend } from "@aws-amplify/backend";
22
import * as s3 from "aws-cdk-lib/aws-s3";
33
import { auth } from "./auth/resource";
4-
import { storage } from "./storage/resource";
4+
import { firstBucket, secondBucket } from "./storage/resource";
55

66
/**
77
* @see https://docs.amplify.aws/react/build-a-backend/ to add storage, functions, and more
88
*/
99
const backend = defineBackend({
1010
auth,
11-
storage,
11+
firstBucket,
12+
secondBucket,
1213
});
1314

1415
// custom storage configurations
15-
const s3Bucket = backend.storage.resources.bucket;
16+
const s3Bucket = backend.firstBucket.resources.bucket;
1617
const cfnBucket = s3Bucket.node.defaultChild as s3.CfnBucket;
18+
const s3SecondaryBucket = backend.secondBucket.resources.bucket;
19+
const cfnSecondaryBucket = s3SecondaryBucket.node.defaultChild as s3.CfnBucket;
1720

1821
cfnBucket.accelerateConfiguration = {
1922
accelerationStatus: "Enabled",
2023
};
2124

25+
cfnSecondaryBucket.accelerateConfiguration = {
26+
accelerationStatus: "Enabled",
27+
};
28+
29+
// required to add the metadata header, which amplify-backend does not support
30+
backend.firstBucket.resources.cfnResources.cfnBucket.corsConfiguration = {
31+
corsRules: [
32+
{
33+
allowedHeaders: ["*"],
34+
allowedMethods: ["GET", "HEAD", "PUT", "POST", "DELETE"],
35+
allowedOrigins: ["*"],
36+
exposedHeaders: [
37+
"x-amz-server-side-encryption",
38+
"x-amz-request-id",
39+
"x-amz-id-2",
40+
"ETag",
41+
"x-amz-meta-description",
42+
],
43+
maxAge: 3000,
44+
},
45+
],
46+
};
47+
2248
// required to add the metadata header, which amplify-backend does not support
23-
backend.storage.resources.cfnResources.cfnBucket.corsConfiguration = {
49+
backend.secondBucket.resources.cfnResources.cfnBucket.corsConfiguration = {
2450
corsRules: [
2551
{
2652
allowedHeaders: ["*"],

0 commit comments

Comments
 (0)