So, I have a React app hosted on a AWS S3 bucket (It also has a CloudFront distribution before it). Using a GitHub Actions workflow, I deploy my build output on S3 with aws-cli s3 sync command:
aws s3 sync build s3://mybucket --delete --acl public-read
Now, I want to perform static file caching with the denoted starting configuration in the CreateReactApp docs:
Cache-Control: max-age=31536000
forbuild/static
assets,Cache-Control: no-cache
for everything else (to ensure the browser will always check for an updated index.html file)
Question
How can I achieve applying such conditional configuration on S3 objects based on the file/folder paths?
What I thought/tried so far
- First I thought it could be done with a setting on the S3 bucket. But after some searching, now, my understanding is that there is no such setting on the bucket itself (at least, answers to this post propose none).
- Then, I headed to
--cache-control
flag of aws cli s3 sync docs, but not did I find a direct, one-liner way of applying different cache controls.