To host a static website on S3, you need to enable static website hosting on the bucket and configure the index and error documents.
Example:
import boto3
s3 = boto3.client('s3')
bucket_name = 'my-website-bucket'
# Enable static website hosting
s3.put_bucket_website(
Bucket=bucket_name,
WebsiteConfiguration={
'IndexDocument': {'Suffix': 'index.html'},
'ErrorDocument': {'Key': 'error.html'}
}
)
print(f"Static website hosting has been enabled for {bucket_name}")