Skip to content

Instantly share code, notes, and snippets.

@GraySmith00
Last active April 20, 2020 01:17
Show Gist options
  • Save GraySmith00/130a43501333eb03b65f4176e6da1c45 to your computer and use it in GitHub Desktop.
Save GraySmith00/130a43501333eb03b65f4176e6da1c45 to your computer and use it in GitHub Desktop.

Gatsby Deploy on AWS s3 + Cloudfront

Resources

Bucket setup

  • New bucket
  • Remove block public access

Bucket Policy

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": [
                "s3:GetObject"
            ],
            "Resource": [
                "arn:aws:s3:::bay-meadow-farms/*"
            ]
        }
    ]
}

CORS Config

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>GET</AllowedMethod>
    <MaxAgeSeconds>3000</MaxAgeSeconds>
    <AllowedHeader>Authorization</AllowedHeader>
    <AllowedHeader>Content-Length</AllowedHeader>
</CORSRule>
</CORSConfiguration>

Gatsby Plugin s3

yarn add gatsby-plugin-s3

gatsby-config.js

{
  resolve: `gatsby-plugin-s3`,
  options: {
    bucketName: "bay-meadow-farms",
    acl: null,
    region: "us-west-1",
    // protocol: "https",
    // hostname: process.env.REACT_APP_HOST_NAME || "fake-host",
  },
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment