aws / aws-sdk-cpp

AWS SDK for C++
Apache License 2.0
1.96k stars 1.05k forks source link

S3Crt GetObject failure #2892

Closed pr0g closed 5 months ago

pr0g commented 6 months ago

Describe the bug

From an OS only environment in Lambda, using the S3CrtClient with the new provided.al2023 runtime, and calling GetObject on the client, results in an internal failure:

[INFO] 2024-03-15 22:08:18.518 S3Client [xxx] id=0x555555d93f10 Initiating making of meta request
[INFO] 2024-03-15 22:08:18.518 connection-manager [xxx] id=0x555555e6a080: Successfully created
[INFO] 2024-03-15 22:08:18.518 S3Client [xxx] id=0x555555d93f10: Created meta request 0x555555e69a80
[INFO] 2024-03-15 22:08:18.518 S3MetaRequest [xxx] id=0x555555e69a80: Doing a 'GET_OBJECT_WITH_RANGE' to discover the size of the object and get the first part
[INFO] 2024-03-15 22:08:18.518 S3MetaRequest [xxx] id=0x555555e69a80: Doing a ranged get to discover the size of the object and get the first part
[INFO] 2024-03-15 22:08:18.518 S3ClientStats [xxx] id=0x555555d93f10 Requests-in-flight(approx/exact):1/1  Requests-preparing:1  Requests-queued:0  Requests-network(get/put/default/total):0/0/0/0  Requests-streaming-waiting:0  Requests-streaming-response:0  Endpoints(in-table/allocated):1/1
[INFO] 2024-03-15 22:08:18.518 AuthSigning [xxx] (id=0x7f1450001c90) Signing successfully built canonical request for algorithm SigV4, with contents 
...
[INFO] 2024-03-15 22:08:18.518 AuthSigning [xxx] (id=0x7f1450001c90) Signing successfully built string-to-sign via algorithm SigV4, with contents 
[INFO] 2024-03-15 22:08:18.518 AuthSigning [xxx] (id=0x7f1450001c90) Http request successfully built final authorization value via algorithm SigV4, with contents 
...
[ERROR] 2024-03-15 22:08:18.536 S3MetaRequest [xxx] id=0x555555e69a80: Request 0x7f1470001850 could not append to response body due to error 26 (Destination of copy is too small.)
[ERROR] 2024-03-15 22:08:18.536 http-stream [xxx] id=0x7f146c0158c0: Incoming body callback raised error 26 (AWS_ERROR_DEST_COPY_TOO_SMALL).
[ERROR] 2024-03-15 22:08:18.536 http-connection [xxx] id=0x7f146c02f630: Message processing failed, error 26 (AWS_ERROR_DEST_COPY_TOO_SMALL). Closing connection.

Calling code looks roughly like this:

download(Aws::S3Crt::S3CrtClient const& s3Client, Aws::String const& bucketIn, Aws::String const& keyIn) {
    S3Crt::Model::GetObjectRequest getRequest;
    getRequest.WithBucket(bucketIn).WithKey(keyIn);

    auto outcome = s3Client.GetObject(getRequest); // fails

This code is running as a native Lambda function. The infrastructure is provisioned by Terraform and previously was using "provided" (instead of "provided.al2023"). With "provided" things worked as expected. It seems like the problem is potentially an issue to do with aws-c-common as the enum reported comes from here.

As a quick test I switched out S3Crt with the normal S3 client libraries and things worked exactly as expected. This is a workaround for now but it definitely seems something is going wrong inside the S3Crt library.

(see https://aws.amazon.com/blogs/compute/introducing-the-amazon-linux-2023-runtime-for-aws-lambda/ for more context).

Expected Behavior

S3Crt library works as expected in the "provided.al2023" environment.

Current Behavior

S3Crt suffers an internal failure.

Reproduction Steps

See description above, it should be possible to repro using the above environment (OS only environment with Amazon Linux 2023) and the S3Crt example here. What we're doing is very similar.

Possible Solution

Use the S3 client instead of S3Crt (not sure what the performance implications are at this stage though).

Additional Information/Context

No response

AWS CPP SDK version used

1.11.255 (from vcpkg)

Compiler and Version used

gcc

Operating System and version

Amazon Linux 2023

sbiscigl commented 6 months ago

Expected Behavior S3Crt library works as expected in the "provided.al2023" environment.

I tried reproducing the issue with the following set up and could not.

Dockerfile

FROM public.ecr.aws/lambda/provided:al2023

#install deps
RUN dnf install -y git cmake gcc-c++ libcurl-devel zlib-devel openssl-devel

# Clone repo
RUN git clone --depth 1 --recurse-submodules https://github.com/aws/aws-sdk-cpp && \
    cd aws-sdk-cpp && \
    mkdir build && \
    cd build && \
    cmake -DAUTORUN_UNIT_TESTS=OFF -DBUILD_ONLY="s3-crt" .. && \
    cmake --build . && \
    cmake --install .

# Copy Code Over \
RUN mkdir sdk-example
COPY CMakeLists.txt sdk-example/CMakeLists.txt
COPY main.cpp sdk-example/main.cpp
RUN cd sdk-example && \
    mkdir build && \
    cd build && \
    cmake .. -DUSE_CRT=ON && \
    cmake --build .

ENTRYPOINT [ "./sdk-example/build/sdk_usage_workspace" ]

main.cpp

#include <aws/core/Aws.h>
#ifdef USE_CRT
#include <aws/s3-crt/S3CrtClient.h>
#include <aws/s3-crt/model/PutObjectRequest.h>
#include <aws/s3-crt/model/GetObjectRequest.h>
#else
#include <aws/s3/S3Client.h>
#include <aws/s3/model/PutObjectRequest.h>
#include <aws/s3/model/GetObjectRequest.h>
#endif

using namespace Aws;
using namespace Aws::Utils;
#ifdef USE_CRT
using namespace Aws::S3Crt;
using namespace Aws::S3Crt::Model;
#else
using namespace Aws::S3;
using namespace Aws::S3::Model;
#endif

const char* ALLOCATION_TAG = "sure";
const char* BUCKET_NAME = "yourbucketname";

auto main() -> int {
  SDKOptions options;
  options.loggingOptions.logLevel = Logging::LogLevel::Trace;
  InitAPI(options); {
#ifdef USE_CRT
    const auto client = MakeUnique<S3CrtClient>(ALLOCATION_TAG);
#else
    const auto client = MakeUnique<S3Client>(ALLOCATION_TAG);
#endif

    auto putRequest = PutObjectRequest().WithBucket(BUCKET_NAME).WithKey("some-test-key");

    std::shared_ptr<IOStream> body = Aws::MakeShared<StringStream>(ALLOCATION_TAG,
      "test string",
      std::ios_base::in | std::ios_base::binary);

    putRequest.SetBody(body);

    const auto putResponse = client->PutObject(putRequest);
    assert(putResponse.IsSuccess());

    auto getRequest = GetObjectRequest().WithBucket(BUCKET_NAME).WithKey("some-test-key");
    const auto getResponse = client->GetObject(getRequest);
    assert(getResponse.IsSuccess());
    std::cout << getResponse.GetResult().GetBody().rdbuf();
  }
  ShutdownAPI(options);
  return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.13)
project(sdk_usage_workspace)
set(CMAKE_CXX_STANDARD 20)
find_package(AWSSDK REQUIRED COMPONENTS s3-crt)
if (USE_CRT)
    add_definitions("-DUSE_CRT")
endif ()
add_executable(${PROJECT_NAME} "main.cpp")
target_link_libraries(${PROJECT_NAME} ${AWSSDK_LINK_LIBRARIES})

when i build with

docker build -t basic-use-image .

and i run with

docker run \
    -e AWS_ACCESS_KEY_ID=... \
    -e AWS_SECRET_ACCESS_KEY=... \
    -e AWS_SESSION_TOKEN=... \
    --name basic-use-image basic-use-image /sdk-example/build/sdk_usage_workspace

I see the output "test string". So this uses the provided:al2023 docker images which according to docs is what image is being used.

Since we cannot reproduce in the image, could you possibly try to update this example to replicate what you are seeing?

pr0g commented 6 months ago

Thank you very much for getting back to me about this issue @sbiscigl, much appreciated!

I will see if I can put together a smaller reproduction case later this week, I'll do my best to follow-up. If I run out of time I'll leave an update and try and provide more info if I can.

Thank you for your help

github-actions[bot] commented 6 months ago

Greetings! It looks like this issue hasn’t been active in longer than a week. We encourage you to check if this is still an issue in the latest release. Because it has been longer than a week since the last update on this, and in the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or add an upvote to prevent automatic closure, or if the issue is already closed, please feel free to open a new one.

pr0g commented 6 months ago

Hi there,

I'm pretty sure this is still an issue, I just haven't had an opportunity to test again after switching to normal S3 instead of S3Crt. I will see if I can repro soon and will do my best to update the ticket with more details.

Thanks,

DmitriyMusatkin commented 5 months ago

Fix has been merged in https://github.com/aws/aws-sdk-cpp/commit/3abf409c171d60c874015d5962e79902a5f3ad1d and should be available in the next release later today

pr0g commented 5 months ago

This is awesome to hear @DmitriyMusatkin! 😄 Thanks very much for the update, I'll keep an eye on when the release is published! 🥳

github-actions[bot] commented 5 months ago

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.