Updated 27/09/2024
I needed to pop a static website into a S3 bucket because its current containerised hosting in AWS Lightsail was proving to be problematic with new deploys (wierd javascript errors) and attracting a higher hosting cost. (EC2 compute to run the container service)
Lucky for me I work with legends who have already figured this out so most of the below is based on the work done by Jaco Brink - cheers brother!
AWS Config
The below assumes your AWS CLI is installed and configured.
Note the user will need permissions policies AmazonS3FullAccess and AWSCloudFormationFullAccess. Hopefully you add these via a user group and not attach directly like a moegoe 😐
Create the Bucket
Cloud formation is the weapon of choice when deploying infrastructure. Its repeatable and then managed by AWS.
The cloud formation template data here is kept in porky-bucket-website.json because YML hurts my brain.
porky-bucket-website.json
| 1 | { | 
Now run the cloudformation comand:
| 1 | aws cloudformation create-stack --stack-name PorkyBucketWebsiteStack --template-body file://./aws-deploy/porky-bucket-website.json --profile infrauser --region ap-southeast-2 | 
You can also run with update-stack to update.
- https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket.html
- https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-policy-language-overview.html
Deploy website
Now after publishing your code to ./pub deploy it to the bucket.
| 1 | aws s3 sync './pub' 's3://ums-audits' --acl public-read --profile infrauser --region ap-southeast-2 | 
The DNS is avalible from the AWS Console -> Amazon S3 -> Buckets/porky-bucket-website -> Properties -> Static website hosting
By default this will not have HTTPS.