-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c02c03
commit be6de2c
Showing
3 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
javav2/example_code/s3/src/main/java/com/example/s3/GetObjectUrl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
javav2/example_code/s3/src/main/java/com/example/s3/ListBuckets.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.example.s3; | ||
|
||
// snippet-start:[s3.java2.list.buckets.main] | ||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.services.s3.S3Client; | ||
import software.amazon.awssdk.services.s3.model.Bucket; | ||
import software.amazon.awssdk.services.s3.model.ListBucketsResponse; | ||
import java.util.List; | ||
|
||
/** | ||
* Before running this Java V2 code example, set up your development | ||
* environment, including your credentials. | ||
* | ||
* For more information, see the following documentation topic: | ||
* | ||
* https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html | ||
*/ | ||
public class ListBuckets { | ||
public static void main(String[] args) { | ||
Region region = Region.US_EAST_1; | ||
S3Client s3 = S3Client.builder() | ||
.region(region) | ||
.build(); | ||
|
||
listAllBuckets(s3); | ||
|
||
} | ||
public static void listAllBuckets(S3Client s3) { | ||
ListBucketsResponse response = s3.listBuckets(); | ||
List<Bucket> bucketList = response.buckets(); | ||
for (Bucket bucket: bucketList) { | ||
System.out.println("Bucket name "+bucket.name()); | ||
} | ||
} | ||
} | ||
// snippet-end:[s3.java2.list.buckets.main] |