AWS Code Sample
Catalog

list_buckets.cpp

list_buckets.cpp demonstrates how to list all the buckets in an AWS account.

/* Copyright 2010-2017 Amazon.com, 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 http://aws.amazon.com/apache2.0/ 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. */ #include <aws/core/Aws.h> #include <aws/s3/S3Client.h> #include <aws/s3/model/Bucket.h> /** * List your Amazon S3 buckets. */ int main(int argc, char** argv) { Aws::SDKOptions options; Aws::InitAPI(options); { Aws::S3::S3Client s3_client; auto outcome = s3_client.ListBuckets(); if (outcome.IsSuccess()) { std::cout << "Your Amazon S3 buckets:" << std::endl; Aws::Vector<Aws::S3::Model::Bucket> bucket_list = outcome.GetResult().GetBuckets(); for (auto const &bucket : bucket_list) { std::cout << " * " << bucket.GetName() << std::endl; } } else { std::cout << "ListBuckets error: " << outcome.GetError().GetExceptionName() << " - " << outcome.GetError().GetMessage() << std::endl; } } Aws::ShutdownAPI(options); }

Sample Details

Service: s3

Author: AWS

Type: full-example

On this page: