Using an Amazon S3 Bucket as a Static Web Host

An S3 bucket can be configured to host a static website.

Retrieve a Website Configuration

Retrieve a bucket's website configuration by calling the AWS SDK for Python get_bucket_website method.

import boto3

# Retrieve the website configuration
s3 = boto3.client('s3')
result = s3.get_bucket_website('BUCKET_NAME')

Set a Website Configuration

A bucket's website configuration can be set by calling the put_bucket_website method.

# Define the website configuration
website_configuration = {
    'ErrorDocument': {'Key': 'error.html'},
    'IndexDocument': {'Suffix': 'index.html'},
}

# Set the website configuration
s3 = boto3.client('s3')
s3.put_bucket_website('BUCKET_NAME', website_configuration)

Delete a Website Configuration

A bucket's website configuration can be deleted by calling the delete_bucket_website method.

# Delete the website configuration
s3 = boto3.client('s3')
s3.delete_bucket_website('BUCKET_NAME')