Tim V
01/31/2022, 11:56 PMDevin
02/01/2022, 12:41 AMconst bucket = new sst.Bucket(this, "MyCoolBucket", {
s3Bucket: {
cors: [
{
maxAge: 3000,
allowedOrigins: ["*"],
allowedHeaders: ["*"],
allowedMethods: ["GET", "PUT", "POST", "DELETE", "HEAD"],
},
],
// Delete all the files
autoDeleteObjects: true,
// Remove the bucket when the stack is removed
removalPolicy: cdk.RemovalPolicy.DESTROY,
},
// notifications etc...
Then I have a react app, which I pass up the bucket info to
const reactApp = new sst.ReactStaticSite(this, "ReactSite", {
path: "frontend",
environment: {
REACT_APP_REGION: scope.region, // the region and the name
REACT_APP_BUCKET_NAME: bucket.bucketName,
// whatever else I want
},
On the front end I configure the bucket with Amplify
Amplify.configure({
API: {
// some stuff
},
Auth: {
// other stuff
},
Storage: {
region: config.s3.REGION,
bucket: config.s3.BUCKET,
},
the config file is basically
s3: {
REGION: process.env.REACT_APP_REGION,
BUCKET: process.env.REACT_APP_BUCKET_NAME,
},
Tim V
02/01/2022, 2:56 PM