Aws::SDKOptions options;
options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Info;
Aws::InitAPI(options);
{
Aws::Client::ClientConfiguration opts;
opts.scheme = Aws::Http::Scheme::HTTP;
opts.region = Aws::String("");
opts.endpointOverride = "13.70.0.324:8080";;
opts.verifySSL = false;
opts.connectTimeoutMs = 60000;
opts.requestTimeoutMs = 10000;
Aws::S3::S3Client s3_client(Aws::Auth::AWSCredentials(access_key_id, secret_access_key),
opts);
auto outcome = s3_client.ListBuckets();
if (outcome.IsSuccess()) {
Aws::String SourceImageBucket("sourceimages");
Aws::String DestnImageBucket("test");
std::cout << "Your S3 buckets:" << std::endl;
Aws::Vector<Aws::S3::Model::Bucket> bucket_list =
outcome.GetResult().GetBuckets();
Aws::Vector<Aws::S3::Model::Bucket>::const_iterator source_bucket;
Aws::Vector<Aws::S3::Model::Bucket>::const_iterator destin_bucket;
for(Aws::Vector<Aws::S3::Model::Bucket>::const_iterator it = bucket_list.begin();
it != bucket_list.end(); it++)
{
auto bname = it->GetName();
if (SourceImageBucket.compare(bname) == 0)
{
source_bucket = it;
std::cout << "Source Bucket : " <<
source_bucket->GetName() << std::endl;
}
if (DestnImageBucket.compare(bname) == 0)
{
destin_bucket = it;
std::cout << "Destination Bucket : " <<
destin_bucket->GetName() << std::endl;
}
}
Aws::S3::Model::ListObjectsRequest objects_request;
objects_request.WithBucket(DestnImageBucket);
// The following command fails
auto list_objects_outcome = s3_client.ListObjects(objects_request);
if (list_objects_outcome.IsSuccess()) {
Aws::Vector<Aws::S3::Model::Object> object_list =
list_objects_outcome.GetResult().GetContents();
for (auto const &s3_object : object_list) {
std::cout << "* " << s3_object.GetKey() << std::endl;
}
}
else {
std::cout << "ListObjects error: " <<
list_objects_outcome.GetError().GetExceptionName() << " " <<
list_objects_outcome.GetError().GetMessage() << std::endl;
}
}
else {
std::cout << "ListBuckets error: "
<< outcome.GetError().GetExceptionName() << " - "
<< outcome.GetError().GetMessage() << std::endl;
}
}
Aws::ShutdownAPI(options);