- AWS Code Sample demonstrates how to get a list of buckets in your AWS account.

/* Copyright 2010-2019, Inc. or its affiliates. All Rights Reserved. This file is licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package aws.example.s3; import com.amazonaws.regions.Regions; import; import; import; import java.util.List; /** * List your Amazon S3 buckets. * * This code expects that you have AWS credentials set up per: * */ public class ListBuckets { public static void main(String[] args) { final AmazonS3 s3 = AmazonS3ClientBuilder.standard().withRegion(Regions.DEFAULT_REGION).build(); List<Bucket> buckets = s3.listBuckets(); System.out.println("Your Amazon S3 buckets are:"); for (Bucket b : buckets) { System.out.println("* " + b.getName()); } } }

Sample Details

Service: s3

Author: soo-aws

Type: full-example