_site
directory to the AWS S3 bucketBucketName
must match your domain name exactlyPublicAccessBlockConfiguration
properties are all set to false in order to allow public access to your websiteBucketPolicy
has s3:GetObject
action set to allow so that anyone can read the object data and view the websiteWebsiteConfiguration
enables the static website capability in S3WWWBucket
creates an empty bucket only used to redirect www.FIXME.com traffic to your FIXME.com bucket; only needed if you decide to not use a CloudFront CDN and just host unencrypted content from S3 only (which is what I did initially)---
AWSTemplateFormatVersion: '2010-09-09'
Description: Simple S3 Bucket to host static public website.
Resources:
S3Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: FIXME.com
PublicAccessBlockConfiguration:
BlockPublicAcls: false
BlockPublicPolicy: false
IgnorePublicAcls: false
RestrictPublicBuckets: false
Tags:
-
Key: Description
Value: FIXME
- Key: Project
Value: FIXME.com
VersioningConfiguration:
Status: Enabled
WebsiteConfiguration:
ErrorDocument: 404.html
IndexDocument: index.html
BucketPolicyDataSync:
Type: 'AWS::S3::BucketPolicy'
Properties:
Bucket: !Ref S3Bucket
PolicyDocument:
Statement:
-
Sid: "AllowAccesToIAMRole"
Action:
- "s3:GetObject"
Effect: "Allow"
Resource:
Fn::Join:
- ""
-
- "arn:aws:s3:::"
-
Ref: "S3Bucket"
- "/*"
Principal: "*"
WWWBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: www.FIXME.com
AccessControl: BucketOwnerFullControl
WebsiteConfiguration:
RedirectAllRequestsTo:
HostName: FIXME.com
Outputs:
S3BucketName:
Value: !Ref S3Bucket
Description: S3 Bucket for object storage
S3BucketARN:
Value: !GetAtt S3Bucket.Arn
Description: S3 bucket ARN
Your Route 53 domain must have completed registration before you can request to validate it with a new ACM cert. It can take 30+ minutes for your SSL cert to be validated, meanwhile you can move onto the IAM policy/user creation steps below. Don’t forget to request your ACM cert from us-east-1 which is the only region supported by Cloudfront!
{
"Version": "2012-10-17",
"Statement": [
{
"Resource": [
"arn:aws:s3:::FIXME-bucket-name",
"arn:aws:s3:::FIXME-bucket-name/*"
],
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": [
"s3:*"
]
},
{
"Sid": "VisualEditor2",
"Effect": "Allow",
"Action": "cloudfront:*",
"Resource": "arn:aws:cloudfront::FIXME-aws-account-number:distribution/FIXME-distribution-id"
}
]
}
build-and-deploy.yml
name: CI / CD
# Controls when the action will run.
on:
# Triggers the workflow on push for the main branch
push:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
env:
AWS_ACCESS_KEY_ID: $
AWS_SECRET_ACCESS_KEY: $
AWS_DEFAULT_REGION: 'FIXME'
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
bundler-cache: true
- uses: actions/cache@v2
with:
path: vendor/bundle
key: $-gems-$
restore-keys: |
$-gems-
- name: Install dependencies
run: |
gem install bundler
gem install jekyll
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: "Build Site"
run: bundle exec jekyll build
env:
JEKYLL_PAT: $
- name: "Deploy to AWS S3"
run: aws s3 sync ./_site/ s3://$ --acl public-read --delete --cache-control max-age=604800
- name: "Create AWS Cloudfront Invalidation"
run: aws cloudfront create-invalidation --distribution-id $ --paths "/*"
AWS_ACCESS_KEY_ID
- The AWS access key ID associated with the programmatic IAM User.AWS_SECRET_ACCESS_KEY
- The AWS secret key ID associated with the programmatic IAM User.AWS_S3_BUCKET_NAME
- Your AWS bucket name hosting your website, for example: jennasprattler.com or FIXME.comAWS_CLOUDFRONT_DISTRIBUTION_ID
- The 14 character alphanumeric Cloudfront distribution ID fronting your S3 bucket's website.JEKYLL_PAT
- Setup a GitHub token that can be used by the workflow in order to build the Jekyll _site pages.You now have a functioning, secure, serverless, static website configured for automatic updates upon code commit to your repository.