|
| 1 | +.. Copyright 2010-2017 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 | +Configuring an |s3| Bucket as a Website |
| 13 | +####################################### |
| 14 | + |
| 15 | +.. meta:: |
| 16 | + :description: How to set, retrieve, or delete an S3 bucket's website configuration. |
| 17 | + :keywords: AWS for Java SDK code examples, s3, website, website configuration |
| 18 | + |
| 19 | +You can configure an |s3| bucket to behave as a website. To do this, you need to set its website |
| 20 | +configuration. |
| 21 | + |
| 22 | +.. include:: includes/examples-note.txt |
| 23 | + |
| 24 | +Set a Bucket's Website Configuration |
| 25 | +==================================== |
| 26 | + |
| 27 | +To set an |s3| bucket's website configuration, call the |s3client|'s |
| 28 | +:methodname:`setWebsiteConfiguration` method with the bucket name to set the configuration for, and |
| 29 | +a :aws-java-class:`BucketWebsiteConfiguration <services/s3/model/BucketWebsiteConfiguration>` object |
| 30 | +containing the bucket's website configuration. |
| 31 | + |
| 32 | +Setting an index document is *required*; all other parameters are optional. |
| 33 | + |
| 34 | +**Imports** |
| 35 | + |
| 36 | +.. literalinclude:: example_code/s3/src/main/java/aws/example/s3/SetWebsiteConfiguration.java |
| 37 | + :lines: 15-18 |
| 38 | + |
| 39 | +**Code** |
| 40 | + |
| 41 | +.. literalinclude:: example_code/s3/src/main/java/aws/example/s3/SetWebsiteConfiguration.java |
| 42 | + :dedent: 8 |
| 43 | + :lines: 31-50 |
| 44 | + |
| 45 | +.. note:: Setting a website configuration does not modify the access permissions for your bucket. |
| 46 | + To make your files visible on the web, you will also need to set a *bucket policy* that allows |
| 47 | + public read access to the files in the bucket. For more information, see |
| 48 | + :doc:`examples-s3-bucket-policies`. |
| 49 | + |
| 50 | +See the :sdk-examples-java-s3:`complete example <SetWebsiteConfiguration.java>`. |
| 51 | + |
| 52 | + |
| 53 | +Get a Bucket's Website Configuration |
| 54 | +==================================== |
| 55 | + |
| 56 | +To get an |s3| bucket's website configuration, call the |s3client|'s |
| 57 | +:methodname:`getWebsiteConfiguration` method with the name of the bucket to retrieve the |
| 58 | +configuration for. |
| 59 | + |
| 60 | +The configuration will be returned as a :aws-java-class:`BucketWebsiteConfiguration |
| 61 | +<services/s3/model/BucketWebsiteConfiguration>` object. If there is no website configuration for the |
| 62 | +bucket, then :code-java:`null` will be returned. |
| 63 | + |
| 64 | +**Imports** |
| 65 | + |
| 66 | +.. literalinclude:: example_code/s3/src/main/java/aws/example/s3/GetWebsiteConfiguration.java |
| 67 | + :lines: 15-18 |
| 68 | + |
| 69 | +**Code** |
| 70 | + |
| 71 | +.. literalinclude:: example_code/s3/src/main/java/aws/example/s3/GetWebsiteConfiguration.java |
| 72 | + :dedent: 8 |
| 73 | + :lines: 30-46 |
| 74 | + |
| 75 | +See the :sdk-examples-java-s3:`complete example <GetWebsiteConfiguration.java>`. |
| 76 | + |
| 77 | + |
| 78 | +Delete a Bucket's Website Configuration |
| 79 | +======================================= |
| 80 | + |
| 81 | +To delete an |s3| bucket's website configuration, call the |s3client|'s |
| 82 | +:methodname:`deleteWebsiteConfiguration` method with the name of the bucket to delete the |
| 83 | +configuration from. |
| 84 | + |
| 85 | +**Imports** |
| 86 | + |
| 87 | +.. literalinclude:: example_code/s3/src/main/java/aws/example/s3/DeleteWebsiteConfiguration.java |
| 88 | + :lines: 15-17 |
| 89 | + |
| 90 | +**Code** |
| 91 | + |
| 92 | +.. literalinclude:: example_code/s3/src/main/java/aws/example/s3/DeleteWebsiteConfiguration.java |
| 93 | + :dedent: 8 |
| 94 | + :lines: 29-36 |
| 95 | + |
| 96 | +See the :sdk-examples-java-s3:`complete example <DeleteWebsiteConfiguration.java>`. |
| 97 | + |
| 98 | + |
| 99 | +More Information |
| 100 | +================ |
| 101 | + |
| 102 | +* :s3-api:`PUT Bucket website <RESTBucketPUTwebsite>` in the |s3-api| |
| 103 | +* :s3-api:`GET Bucket website <RESTBucketGETwebsite>` in the |s3-api| |
| 104 | +* :s3-api:`DELETE Bucket website <RESTBucketDELETEwebsite>` in the |s3-api| |
| 105 | + |
0 commit comments