Hey all, curious if anyone has a good workflow for...
# help
r
Hey all, curious if anyone has a good workflow for SST local dev and working with s3 files. I would like to have a bunch of JSON files in a local folder, read/write to them locally when doing local dev. Then when I deploy I would like those files to be sync'd to an s3 bucket and my read/write to work against s3. Maybe everything needs to be on s3, even during local dev? Any ideas on a clean way to work this?
r
Typically I just use s3 locally too. All I can think of as an alternative is to abstract away the s3 access, implement a file system based adapter and then switch it based on an env var driven by the stack local property. Seems like a lot of work unless there's a really good reason not to use s3 in all scenarios. Why is it you don't want to do that?
r
So how do you sync the files? Like i imagine there is a folder in your SST project like
s3-stuff
how do you get that up to the bucket when you start local dev? i would be very happy to just use s3 always, just wanna make sure the workflow is there.
r
How do they get there in the deployed state?
r
That's another great question haha. My first thought was to use a script, but SST scripts run in a lambda not locally so I don't think I can get access to the files. I could write my own script and run it after deploy though. Something simple that just uses a simple sync like this https://www.npmjs.com/package/s3-sync-client Another option I was thinking is hacking it together with a StaticSite. Seeing that it already takes local files and puts them into a s3 bucket, I would just ditch the cloudfront part of it and essentially try to make it a static file s3 uploader. This wouldn't do a sync though, which isn't ideal Neither are great, which I think is the root of my problem 🙂 I would like to use s3 JSON as a data source instead of a DB. The changes are not frequent and there would be a lot of benefits for what I am doing from a simple cached file. I am just not sure the best way to get the files up there, during deploy and local dev, using SST/CDK concepts. It seems like I am probably looking for some way to run a script after local dev/deploy that has access to the CDK outputs. Although if I could get a similar
hook
syntax for
Bucket
that we have for
Function
that would be good, or even better a Bucket construct that could take a file path and sync it on deploy and
start
itself.
f
@Ross Gerbasi You can use CDK’s BucketDeployment construct https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3_deployment.BucketDeployment.html It does the S3 syncing similar to StaticSite, without the CF stuff.
That said, I’d probably use S3 locally as well 🤓
r
@Frank does SST provide any helpers to get the root path. so when I specify a folder for the deploy like this
Copy code
sources: [s3deploy.Source.asset(path.join(__dirname, 'my-website'))],
_dirname
will be somewhere in the build folder, is there an easy way to get the root of the project?