I send a HeadBucketRequest like so
// Check if the bucket exists
s3::S3Client client;
s3::Model::HeadBucketRequest head_request;
head_request.WithBucket(bucket.c_str());
auto head_bucket_outcome = client.HeadBucket(head_request);
if (!head_bucket_outcome.IsSuccess()) {
return Status(
RequestStatusCode::INTERNAL,
"Could not get metadata for bucket with name " + bucket);
}
The outcome shows failure, and when I print out the outcome I see that I'm receiving an
Aws::S3::S3Errors::ACCESS_DENIED. On the same machine, the awscli works fine. I have my credentials stored in ~/.aws/credentials. I feel like there is something basic I am missing here. Perhaps I'm not initiliazing the client correctly?
Ubuntu 18.04
1.7.129
gcc/g++ 7.4.0
I add the project with these commands
ExternalProject_Add(aws-sdk-cpp
PREFIX aws-sdk-cpp
GIT_REPOSITORY "https://github.com/aws/aws-sdk-cpp.git"
GIT_TAG "1.7.129"
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/aws-sdk-cpp/src/aws-sdk-cpp"
CMAKE_CACHE_ARGS
-DBUILD_ONLY:STRING=s3
-DBUILD_SHARED_LIBS:BOOL=ON
-DMINIMIZE_SIZE:BOOL=ON
-DENABLE_TESTING:BOOL=OFF
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/aws-sdk-cpp/install
)
Add includes to my files with this
target_include_directories(
server-library
PRIVATE $<TARGET_PROPERTY:aws-cpp-sdk-s3,INTERFACE_INCLUDE_DIRECTORIES>
)
And link with the following
find_package(AWSSDK REQUIRED COMPONENTS s3)
message(STATUS "Using aws-cpp-sdk-s3 ${AWSSDK_VERSION}")
target_link_libraries(
trtserver
PRIVATE aws-cpp-sdk-s3
)
Hi @xprotobeast2,
The most common reason for this is the region, the sdk does not use the region defined in the .aws/credentials file and defaults to us-east.
Could you try:
Client::ClientConfiguration config;
config.region= "*YOUR_REGION*";
s3::S3Client client(config);
If that doesn't work, please activate the trace log:
options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Trace;
and, after sanitizing for sensitive info, let me see the trace log? That should give us more information on what went wrong.
That seems to have worked, thank you! However, is there anyway to provide the region through an external config file?
Sorry I retried, and turns out ~/.aws/config does NOT work.
Sorry, I wasn't clear on my previous answer, my bad there, I wasn't sure the region was the problem and wanted to test for that, also you're right it's ~/.aws/config that should have this.
So, one solution is to modify ClientConfiguration through code as you did previously.
Now, If you want to use the configuration set on ~/.aws/config then you'd need to add this:
Aws::Client::ClientConfiguration config("NAME OF YOUR PROFILE");
For example, if in your configuration file you have something like:
[default]
region=us-west-2
output=json
[profile user1]
region=us-east-1
output=text
You could do:
Aws::Client::ClientConfiguration config("default");
Let me know if that works for you, and sorry again for the confusion.
@KaibaLopez Yes I stumbled on the same solution. This is working for me. Thank you so much for your timely help.