File tree 3 files changed +49
-2
lines changed
javav2/example_code/s3/src/main/java/com/example/s3
3 files changed +49
-2
lines changed Original file line number Diff line number Diff line change @@ -1971,6 +1971,15 @@ s3_ListBuckets:
1971
1971
synopsis : list S3 buckets.
1972
1972
category :
1973
1973
languages :
1974
+ Java :
1975
+ versions :
1976
+ - sdk_version : 2
1977
+ github : javav2/example_code/s3
1978
+ sdkguide :
1979
+ excerpts :
1980
+ - description :
1981
+ snippet_tags :
1982
+ - s3.java2.list.buckets.main
1974
1983
.NET :
1975
1984
versions :
1976
1985
- sdk_version : 3
Original file line number Diff line number Diff line change 1
1
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
// SPDX-License-Identifier: Apache-2.0
3
- //* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
- *SPDX -License -Identifier :Apache -2.0 */
3
+
5
4
package com .example .s3 ;
6
5
7
6
// snippet-start:[s3.java2.getobjecturl.main]
Original file line number Diff line number Diff line change
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ package com .example .s3 ;
5
+
6
+ // snippet-start:[s3.java2.list.buckets.main]
7
+ import software .amazon .awssdk .regions .Region ;
8
+ import software .amazon .awssdk .services .s3 .S3Client ;
9
+ import software .amazon .awssdk .services .s3 .model .Bucket ;
10
+ import software .amazon .awssdk .services .s3 .model .ListBucketsResponse ;
11
+ import java .util .List ;
12
+
13
+ /**
14
+ * Before running this Java V2 code example, set up your development
15
+ * environment, including your credentials.
16
+ *
17
+ * For more information, see the following documentation topic:
18
+ *
19
+ * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html
20
+ */
21
+ public class ListBuckets {
22
+ public static void main (String [] args ) {
23
+ Region region = Region .US_EAST_1 ;
24
+ S3Client s3 = S3Client .builder ()
25
+ .region (region )
26
+ .build ();
27
+
28
+ listAllBuckets (s3 );
29
+
30
+ }
31
+ public static void listAllBuckets (S3Client s3 ) {
32
+ ListBucketsResponse response = s3 .listBuckets ();
33
+ List <Bucket > bucketList = response .buckets ();
34
+ for (Bucket bucket : bucketList ) {
35
+ System .out .println ("Bucket name " +bucket .name ());
36
+ }
37
+ }
38
+ }
39
+ // snippet-end:[s3.java2.list.buckets.main]
You can’t perform that action at this time.
0 commit comments