Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 6e462f7

Browse files
committed
some updates for S3 example topics
1 parent a2c7f94 commit 6e462f7

4 files changed

+126
-17
lines changed

doc_source/examples-s3-bucket-policies.rst

+8-13
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ You can set the bucket policy for a particular S3 bucket by:
3939
**Code**
4040

4141
.. literalinclude:: example_code/s3/src/main/java/aws/example/s3/SetBucketPolicy.java
42-
:dedent: 6
43-
:lines: 113-119
42+
:dedent: 8
43+
:lines: 82-88
4444

4545

4646
.. _use-s3-bucket-policy-class:
@@ -54,7 +54,8 @@ When providing a bucket policy to :methodname:`setBucketPolicy`, you can do the
5454
* Build the policy using the :aws-java-class:`Policy <auth/policy/Policy>` class
5555

5656
By using the :classname:`Policy` class, you don't have to be concerned about correctly formatting
57-
your text string, as shown in the following example.
57+
your text string. To get the JSON policy text from the :classname:`Policy` class, use its
58+
:methodname:`toJson` method.
5859

5960
**Imports**
6061

@@ -64,23 +65,17 @@ your text string, as shown in the following example.
6465
**Code**
6566

6667
.. literalinclude:: example_code/s3/src/main/java/aws/example/s3/SetBucketPolicy.java
67-
:dedent: 6
68-
:lines: 68-73
69-
70-
To get the JSON policy text from the Policy class, use its :methodname:`toJson` method.
71-
72-
.. literalinclude:: example_code/s3/src/main/java/aws/example/s3/SetBucketPolicy.java
73-
:dedent: 6
74-
:lines: 74
68+
:dedent: 8
69+
:lines: 71-77
7570

7671
The :classname:`Policy` class also provides a :methodname:`fromJson` method that can attempt to
7772
build a policy using a passed-in JSON string. The method validates it to ensure that the text
7873
can be transformed into a valid policy structure, and will fail with an :code-java:`IllegalArgumentException`
7974
if the policy text is invalid.
8075

8176
.. literalinclude:: example_code/s3/src/main/java/aws/example/s3/SetBucketPolicy.java
82-
:dedent: 6
83-
:lines: 56-62
77+
:dedent: 8
78+
:lines: 56-63
8479

8580
You can use this technique to prevalidate a policy that you read in from a file or other means.
8681

doc_source/examples-s3-buckets.rst

+12-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ Creating, Listing, and Deleting |S3| Buckets
1919

2020
Every object (file) in |S3| must reside within a *bucket*, which represents a collection (container)
2121
of objects. Each bucket is known by a *key* (name), which must be unique. For detailed information
22-
about buckets and their configuration, see :s3-dg:`Working with Amazon S3 Buckets <UsingBucket>` in the |s3-dg|.
22+
about buckets and their configuration, see :s3-dg:`Working with Amazon S3 Buckets <UsingBucket>` in
23+
the |s3-dg|.
2324

2425
.. include:: common/s3-note-incomplete-upload-policy.txt
2526

@@ -31,17 +32,22 @@ Create a Bucket
3132
===============
3233

3334
Use the |s3client| client's :methodname:`createBucket` method. The new :aws-java-class:`Bucket
34-
<services/s3/model/Bucket>` is returned.
35+
<services/s3/model/Bucket>` is returned. The :methodname:`createBucket` method will raise an
36+
exception if the bucket already exists.
37+
38+
.. tip:: To check whether a bucket already exists before attempting to create one with the same
39+
name, call the :methodname:`doesBucketExist` method. It will return :code-java:`true` if the
40+
bucket exists, and :code-java:`false` otherwise.
3541

3642
**Imports**
3743

3844
.. literalinclude:: example_code/s3/src/main/java/aws/example/s3/CreateBucket.java
39-
:lines: 15-18
45+
:lines: 15-19
4046

4147
**Code**
4248

4349
.. literalinclude:: example_code/s3/src/main/java/aws/example/s3/CreateBucket.java
44-
:lines: 42-50
50+
:lines: 42-54
4551
:dedent: 8
4652

4753
See the :sdk-examples-java-s3:`complete example <CreateBucket.java>`.
@@ -81,6 +87,8 @@ versioned objects associated with the bucket.
8187
.. note:: The :sdk-examples-java-s3:`complete example <DeleteBucket.java>` includes each of these
8288
steps in order, providing a complete solution for deleting an |S3| bucket and its contents.
8389

90+
.. contents::
91+
:local:
8492

8593
Remove Objects from an Unversioned Bucket Before Deleting It
8694
------------------------------------------------------------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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+

doc_source/examples-s3.rst

+1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ This section provides examples of programming |S3|_ using the |sdk-java|_.
2929
examples-s3-objects
3030
examples-s3-bucket-policies
3131
examples-s3-transfermanager
32+
examples-s3-website-configuration
3233

0 commit comments

Comments
 (0)