Debian Codegraph @

docs/source/guide/s3-example-static-web-host.rst

raw
1 .. Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
3 This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0
4 International License (the "License"). You may not use this file except in compliance with the
5 License. A copy of the License is located at http://creativecommons.org/licenses/by-nc-sa/4.0/.
6
7 This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
8 either express or implied. See the License for the specific language governing permissions and
9 limitations under the License.
10
11
12 ##############################################
13 Using an Amazon S3 bucket as a static web host
14 ##############################################
15
16 An S3 bucket can be configured to host a static website.
17
18
19 Retrieve a website configuration
20 ================================
21
22 Retrieve a bucket's website configuration by calling the AWS SDK for Python
23 ``get_bucket_website`` method.
24
25 .. code-block:: python
26
27 import boto3
28
29 # Retrieve the website configuration
30 s3 = boto3.client('s3')
31 result = s3.get_bucket_website(Bucket='amzn-s3-demo-website-bucket')
32
33
34 Set a website configuration
35 ===========================
36
37 A bucket's website configuration can be set by calling the
38 ``put_bucket_website`` method.
39
40
41 .. code-block:: python
42
43 # Define the website configuration
44 website_configuration = {
45 'ErrorDocument': {'Key': 'error.html'},
46 'IndexDocument': {'Suffix': 'index.html'},
47 }
48
49 # Set the website configuration
50 s3 = boto3.client('s3')
51 s3.put_bucket_website(Bucket='amzn-s3-demo-website-bucket',
52 WebsiteConfiguration=website_configuration)
53
54
55 Delete a website configuration
56 ==============================
57
58 A bucket's website configuration can be deleted by calling the
59 ``delete_bucket_website`` method.
60
61 .. code-block:: python
62
63 # Delete the website configuration
64 s3 = boto3.client('s3')
65 s3.delete_bucket_website(Bucket='amzn-s3-demo-website-bucket')