It's much better to use a purpose made tool for this. Below is a (non-exhaustive) list of tools you could use instead (I use Cloudflare Pages):
- Cloudflare Pages
- GitHub Pages
- AWS Amplify
- Azure Static Web Apps
I am keeping this archived repository around for posterity as it was made during a time when there was not many good options for static webpages.
GitHub action to deploy repo to S3 and clear cloudfront cache
You'll need to do a few things beforehand, this can be automated in CloudFormation or not depending on your skill level.
Pretty straightforward, name it something useful, keep it private
Configure it the way you want. If you want to save money, remove every region except US/Canada, assuming you live in North America.
This is important that you don't just use your regular access keys, to keep up security. Limit it's access to just write access to buckets, and invalidation of CloudFront cache.
Feel free to submit an issue if you need help.