MCPcopy Index your code
hub / github.com/CapSoftware/Cap / createS3Bucket

Function createS3Bucket

apps/web/instrumentation.node.ts:43–84  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

41}
42
43async function createS3Bucket() {
44 const s3Client = new S3Client({
45 endpoint: serverEnv().S3_INTERNAL_ENDPOINT,
46 region: serverEnv().CAP_AWS_REGION,
47 credentials: {
48 accessKeyId: serverEnv().CAP_AWS_ACCESS_KEY ?? "",
49 secretAccessKey: serverEnv().CAP_AWS_SECRET_KEY ?? "",
50 },
51 forcePathStyle: serverEnv().S3_PATH_STYLE,
52 });
53
54 await s3Client
55 .send(new CreateBucketCommand({ Bucket: serverEnv().CAP_AWS_BUCKET }))
56 .then(() => {
57 console.log("Created S3 bucket");
58 return s3Client.send(
59 new PutBucketPolicyCommand({
60 Bucket: serverEnv().CAP_AWS_BUCKET,
61 Policy: JSON.stringify({
62 Version: "2012-10-17",
63 Statement: [
64 {
65 Effect: "Allow",
66 Principal: "*",
67 Action: ["s3:GetObject"],
68 Resource: [`arn:aws:s3:::${serverEnv().CAP_AWS_BUCKET}/*`],
69 },
70 ],
71 }),
72 }),
73 );
74 })
75 .then(() => {
76 console.log("Configured S3 buckeet");
77 })
78 .catch((e) => {
79 if (e instanceof BucketAlreadyOwnedByYou) {
80 console.log("Found existing S3 bucket");
81 return;
82 }
83 });
84}
85
86async function runMigrations() {
87 const isDockerBuild = buildEnv.NEXT_PUBLIC_DOCKER_BUILD === "true";

Callers 1

registerFunction · 0.85

Calls 2

serverEnvFunction · 0.90
sendMethod · 0.45

Tested by

no test coverage detected