https://serverless-stack.com/ logo
#help
Title
# help
a

Albert

01/18/2022, 8:38 PM
does anyone know how to configure logging configurations for an s3 bucket in the sst.Bucket instance in SST ?
s

Sam Hulick

01/18/2022, 8:41 PM
you want the
serverAccessLogsBucket
and
serverAccessLogsPrefix
properties
just note, though, if your bucket is behind a CloudFront distribution, you may want to log the CloudFront distribution, NOT the bucket
a

Albert

01/18/2022, 8:43 PM
Oh perfect, thank you a lot, I was looking for something like DestinationBucket and LogFilePrefix because I am coming from sls so thanks a lot found it in the cdk documentation now 🙌
f

Frank

01/18/2022, 8:43 PM
Yup, elaborating on @Sam Hulick’s suggestion:
Copy code
const logBucket = new sst.Bucket(this, "AccessLogBucket");

const bucket = new sst.Bucket(this, 'MyBucket', {
  s3Bucket: {
    serverAccessLogsBucket: accessLogsBucket.s3Bucket,
    serverAccessLogsPrefix: 'logs',
  },
});
s

Sam Hulick

01/18/2022, 8:44 PM
the reason I mention CloudFront is that the S3 logs won’t reflect actual file access since CF will be caching files. I started with S3 logs and then said “wait a minute.. this won’t tell me how much bandwidth a user is using” 😄
a

Albert

01/18/2022, 8:47 PM
My bucket is not behind a CloudFront so it should be fine for now, thanks a lot I will keep this in mind for the future