Skip to content

Instantly share code, notes, and snippets.

@monkut
Created May 8, 2018 05:35
Show Gist options
  • Save monkut/aa011550d596088ef577ad6d82722a20 to your computer and use it in GitHub Desktop.
Save monkut/aa011550d596088ef577ad6d82722a20 to your computer and use it in GitHub Desktop.
Serving Sphinx Documentation on s3

Build your sphinx document

Assumes you already have a sphinx project installed and a project created

make html

By default this command will build documentation to _build/html

Setup IP restricted S3 Bucket (for use as internal website)

This describes the procedure to setup an S3 bucket.

NOTE: This assumes you have the awscli installed

In order to apply an IP restriction you need to set the bucket policy.

  1. Confirm the current bucket policy:

    aws s3api get-bucket-policy --bucket store-manager-spec
    

    If you don't have a bucket policy defined you will get an error: "... The bucket policy does not exist"

  2. Define your policy document, create a file named ip-restriced-bucket-policy.json and update with the following:

    {
        "Id": "IPLimitedAccessPolicy",
        "Version": "2012-10-17",
        "Statement": [
            {
                "Sid": "AllowTrustedIPs",
                "Effect": "Allow",
                "Principal": "*",
                "Action": "s3:GetObject",
                "Resource": "arn:aws:s3:::MY_BUCKET_NAME/*",
                "Condition": {
                    "IpAddress": {
                        "aws:SourceIp": [
                            "IP_TO_ALLOW/32"
                        ]
                    }
                }
            }
        ]
    }  
    
  3. Set the bucket policy:

aws s3api put-bucket-policy --bucket MY_BUCKET_NAME --policy file://ip-restriced-bucket-policy.json

Send built documentation to s3 bucket

From the _build/html directory run the following command to sync the content of the folder with the remote bucket:

aws s3 sync . s3://MY_BUCKET_NAME/

Configure bucket as static website

The following will configure the s3 bucket to operate as a website at:

aws s3 website s3://MY_BUCKET_NAME/ --index-document index.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment