aws-sdk-cpp icon indicating copy to clipboard operation
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

Open csi-amolpawar opened this issue 2 years ago • 3 comments

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

csi-amolpawar avatar Apr 08 '22 07:04 csi-amolpawar

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.

jmklix avatar Jun 09 '22 22:06 jmklix

Hi @jmklix,

I checked and confirming that object has READ access and it has public read access (see below image)

PublicObjectACL

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.

csi-amolpawar avatar Jun 10 '22 06:06 csi-amolpawar

FYI I'm able to download the same object using Aws::S3::Model::GetObjectRequest api

csi-amolpawar avatar Jun 10 '22 06:06 csi-amolpawar

Should be resolved now, re-open if you have a case where it does not.

sbiscigl avatar Sep 01 '22 20:09 sbiscigl

⚠️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.

github-actions[bot] avatar Sep 01 '22 20:09 github-actions[bot]

Yes, Verified and it is fixed from version 1.9.339 @jmklix @sbiscigl

csi-amolpawar avatar Sep 08 '22 06:09 csi-amolpawar