diff --git a/cpp/example_code/s3/hello_s3/hello_s3.cpp b/cpp/example_code/s3/hello_s3/hello_s3.cpp index 14e4a83c248..904450ab701 100644 --- a/cpp/example_code/s3/hello_s3/hello_s3.cpp +++ b/cpp/example_code/s3/hello_s3/hello_s3.cpp @@ -15,6 +15,9 @@ #include #include #include +#include +using namespace Aws; +using namespace Aws::Auth; /* * A "Hello S3" starter application which initializes an Amazon Simple Storage Service (Amazon S3) client @@ -36,6 +39,13 @@ int main(int argc, char **argv) { Aws::Client::ClientConfiguration clientConfig; // Optional: Set to the AWS Region (overrides config file). // clientConfig.region = "us-east-1"; + + // You don't normally have to test that you are authenticated. But the S3 service permits anonymous requests, thus the s3Client will return "success" and 0 buckets even if you are unauthenticated, which can be confusing to a new user. + auto provider = Aws::MakeShared("alloc-tag"); + auto creds = provider->GetAWSCredentials(); + if (creds.IsEmpty()) { + std::cerr << "Failed authentication" << std::endl; + } Aws::S3::S3Client s3Client(clientConfig); auto outcome = s3Client.ListBuckets();