aws-sdk-cpp
aws-sdk-cpp copied to clipboard
[Aws][S3Crt] : Unable to retrieve public object using Aws::S3Crt::S3CrtClient::GetObject api when credentials are not setup i.e anonymmous
Describe the bug
Unable to retrieve public s3 object using Aws::S3Crt::S3CrtClient::GetObject api when credentials are not setup i.e anonymous credentials
I'm able to retrieve the public s3 object when aws credentials are provided/setup
Expected Behavior
I should able to download s3 public object w/o providing/setup the aws credentials using crt api
Same scenario is worked when we use Aws::S3::S3Client::GetObject api for public object w/ and w/o aws credentials
Current Behavior
Getting below exception for s3 public get object using s3 crt api
[root@94f75002c0cd aws-sdk-cpp]# ./aws_s3_crt_get_public_object
Reading object s3://my-bycket/test/my_object
GetObject error:No response body.
Reproduction Steps
It is easily re producible using below code snippet
#include <iostream>
#include <string>
#include <aws/core/Aws.h>
#include <aws/core/utils/memory/stl/AWSStringStream.h>
#include <aws/core/utils/logging/CRTLogSystem.h>
#include <aws/s3-crt/S3CrtClient.h>
#include <aws/s3-crt/model/GetObjectRequest.h>
static const char ALLOCATION_TAG[] = "s3-crt-getobject-public";
int main(int argc, char* argv[])
{
Aws::SDKOptions options;
options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Trace;
options.loggingOptions.crt_logger_create_fn = []() {
return Aws::MakeShared<Aws::Utils::Logging::DefaultCRTLogSystem>(
ALLOCATION_TAG, Aws::Utils::Logging::LogLevel::Trace);
};
Aws::InitAPI(options);
{
Aws::S3Crt::ClientConfiguration config;
config.region = Aws::Region::US_EAST_1;
config.throughputTargetGbps = 5;
config.partSize = 5 * 1024 * 1024;
Aws::S3Crt::S3CrtClient s3CrtClient(config, Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Never);
Aws::String bucket = "my-bucket";
Aws::String objectKey = "test/my_object";
std::cout << "Reading object s3://" << bucket << "/" << objectKey << std::endl;
Aws::S3Crt::Model::GetObjectRequest request;
request.SetBucket(bucket);
request.SetKey(objectKey);
Aws::S3Crt::Model::GetObjectOutcome outcome = s3CrtClient.GetObject(request);
if(outcome.IsSuccess())
std::cout << outcome.GetResult().GetBody().rdbuf() << std::endl;
else
std::cerr << "GetObject error:" << outcome.GetError().GetMessage() << std::endl;
}
Aws::ShutdownAPI(options);
return 0;
}
build command g++ -o aws_s3_crt_get_public_object aws_s3_crt_get_public_object.cpp -I<Path>/include/ -L<Path>/lib64/ -laws-cpp-sdk-s3-crt -laws-cpp-sdk-core -lssl -lcrypto -lpthread
Possible Solution
No response
Additional Information/Context
No response
AWS CPP SDK version used
AWS SDK for C++ 1.9.230
Compiler and Version used
g++ (GCC) 11.2.0
Operating System and version
Linux 434f62a64297 5.13.0-39-generic #44~20.04.1-Ubuntu SMP Thu Mar 24 16:43:35 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Just making sure you've given the correct policy to allow this. You will need to give READ access to anonymous users. I ask this because if you don't have permission to read the object you will get the response you see back.
Hi @jmklix,
I checked and confirming that object has READ access and it has public read access (see below image)
If not having correct permission to read the s3 object, then error message from Aws::S3Crt::Model::GetObjectRequest api should be specific to access, but getting GetObject error:No response body.
FYI I'm able to download the same object using Aws::S3::Model::GetObjectRequest api
Should be resolved now, re-open if you have a case where it does not.
⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
Yes, Verified and it is fixed from version 1.9.339 @jmklix @sbiscigl