aws / aws-sdk-cpp

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

Aws::Client::ClientConfiguration Region is Undefined in Release Configuration #2669

Open xyzmultimedia opened 10 months ago

xyzmultimedia commented 10 months ago

Describe the bug

Let me first start off by stating that I don't think this is a bug, but I'm missing steps to fix something. The code that I am running is below, which works in Debug configuration but not Release:

#define USE_IMPORT_EXPORT
#define USE_WINDOWS_DLL_SEMANTICS

#include <aws/core/Aws.h>
#include <aws/core/auth/AWSCredentialsProvider.h>
#include <aws/lambda/LambdaClient.h>
#include <aws/lambda/model/ListFunctionsRequest.h>
#include <aws/lambda/model/InvokeRequest.h>
#include <aws/lambda/model/LogType.h>

#include <iostream>
#include <sstream>
#include <string>

#include "json.hpp"

using namespace std;
using namespace nlohmann;

int main() {
    Aws::SDKOptions options;
    Aws::InitAPI(options);

    // Setup credentials
    Aws::Auth::AWSCredentials credentials;
    credentials.SetAWSAccessKeyId("id");
    credentials.SetAWSSecretKey("secret");

    // Setup config
    Aws::Client::ClientConfigurationInitValues values;
    values.shouldDisableIMDS = true;
    Aws::Client::ClientConfiguration clientConfig;
    clientConfig.region = Aws::String("us-east-2"); // xstring's Memmove failure
    Aws::Lambda::LambdaClient client(credentials, clientConfig); // aws Optional.h copy failure

    return 0;
}

This issue has already been addressed by this Stack Overflow post (https://stackoverflow.com/questions/57157624/aws-sdk-c-code-dont-work-on-release-build), where they needed to update their packages.

However, I built my packages from CMake, and I should have the latest code on the main branch, and yet I still run into undefined behavior using xstring's memmove when trying to override the clientConfig.region. My reproduction steps for building are down below, am I missing a step?

Expected Behavior

I expect the code to work in Release Configuration as it did for Debug.

Current Behavior

Release Configuration crashes on trying to override the region by assigning a new string.

Reproduction Steps

Steps to build packages and link it to the project:

  1. Get CMake 3.21.7 and add to PATH
  2. C:\Users\Jason > git clone --recurse-submodules https://github.com/aws/aws-sdk-cpp 2.5 C:\Users\Jason > git submodule update --init --recursive
  3. C:\Users\Jason > mkdir sdk_build
  4. C:\Users\Jason > cd sdk_build
  5. C:\Users\Jason\sdk_build > cmake "..\aws-sdk-cpp" -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="C:/Program Files (x86)/aws-cpp-sdk-all"
  6. C:\Users\Jason\sdk_build > cmake --build . --config=Release
  7. C:\Users\Jason\sdk_build > cmake --install . --config=Release
  8. In Visual Studio, add "C:\Program Files (x86)\aws-cpp-sdk-all\include" to Release Configuration: Additional Include Directories
  9. In Visual Studio, add "aws-cpp-sdk-core.lib;aws-cpp-sdk-s3.lib;aws-c-auth.lib;aws-c-cal.lib;aws-c-common.lib;aws-c-compression.lib;aws-c-event-stream.lib;aws-checksums.lib;aws-c-http.lib;aws-c-io.lib;aws-c-mqtt.lib;aws-crt-cpp.lib;aws-c-s3.lib;aws-c-sdkutils.lib;aws-cpp-sdk-lambda.lib;%(AdditionalDependencies)" to Release Configuration: Additional Dependencies
  10. Copy above libs and corresponding dependencies and add them to the project folder (next to main.cpp)
  11. Build and run in Release mode.

Possible Solution

I'm thinking I need to update per this post (https://stackoverflow.com/questions/57157624/aws-sdk-c-code-dont-work-on-release-build), but clearing everything, git cloning, and confirming I have the latest in the main branch using git submodule update --init --recursive does not fix my issue, so I need to update some other way.

Additional Information/Context

No response

AWS CPP SDK version used

Latest (1.11.162)

Compiler and Version used

Visual Studio 17 2022

Operating System and version

Windows 10, Version 22H2

yasminetalby commented 10 months ago

Hello @xyzmultimedia ,

Thank you very much for your submission. You seem to follow perfectly the steps from our Build the AWS SDK for C++ on Windows in the developer guide. Could you please provide the actual error message you are receiving while attempting to build in release mode?

At a first glance, this issue seems similar to this one and this one.

Could you please attempt the recommended suggestion ( defining USE_IMPORT_EXPORT before including any SDK headers or building the SDK statically using the cmake arguments: -DFORCE_SHARED_CRT=OFF -DBUILD_SHARED_LIBS=OFF) and let me know if one of this suggestion solves your issue or if you are still encountering the same behavior?

Best regards,

Yasmine

github-actions[bot] commented 10 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.

xyzmultimedia commented 10 months ago

Hi Yasmine!

Thank you for helping out. Here is the error as output and how it appears: Exception thrown at 0x00007FF8472913EC (vcruntime140.dll) in AWS-Lambda-Invoke.exe: 0xC0000005: Access violation writing location 0x000001FE00000001. image I also see that clientConfig.region is undefined prior, not empty, which is what is causing issues.

I do have #define USE_IMPORT_EXPORT at the top of my code before any of the SDK headers, but I have been struggling trying to find a way to use the CMake arguments -DFORCE_SHARED_CRT=OFF -DBUILD_SHARED_LIBS=OFF in a Visual Studio project. Unfortunately, because of a framework I'm in, I'm not able to CMake my project (or I lack the knowledge how to do so).

Do you know if there is a way I can pass those arguments while building using .sln and .vcxproj?

Thanks again, Jason

JakeDCW commented 10 months ago

I am also experiencing the same issue as this.

yasminetalby commented 10 months ago

Hello @xyzmultimedia ,

Thank you very much for your response, You can provide these CMake arguments -DFORCE_SHARED_CRT=OFF -DBUILD_SHARED_LIBS=OFF during the Step 5 shared in your reproduction steps as follow:

cmake "..\aws-sdk-cpp" -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="C:/Program Files (x86)/aws-cpp-sdk-all" -DFORCE_SHARED_CRT=OFF -DBUILD_SHARED_LIBS=OFF

Unfortunately, I can't provide guidance on building the sdk using .sln and .vcxproj. For support and guidance on this you would need to contact the Microsoft team members and community contributors.

I wonder if our documentation to build our sdk examples using Visual Studio: https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/getting-started-code-examples.html might be helpful for you here.

Let me know if this helps!

Best regards,

Yasmine

yasminetalby commented 10 months ago

Hello @JakeDCW ,

Thank you very much for reaching out. Could you please provide more context? This is a build issue:

Best regards

JakeDCW commented 10 months ago

I am following this guide here: https://aws.amazon.com/blogs/gametech/how-to-integrate-the-aws-c-sdk-with-unreal-engine/ https://aws.amazon.com/blogs/gametech/generate-custom-game-events-from-unreal-integrated-with-the-game-analytics-pipeline/

This is with Unreal 5.2 and VS 2019 and 2022; Using vcpkg or compiling from source with CMake fails on destructor.

https://aws.amazon.com/blogs/gametech/generate-custom-game-events-from-unreal-integrated-with-the-game-analytics-pipeline/

Both compile, but whenever you hit this step here "Replace the BeginPlay function in MyActor.cpp:" in the above link, sometimes it works (first time run) but then whenever a second run happens, there is a crash on destructor of CognitoIdentityClient related functions.

yasminetalby commented 10 months ago

Hello @JakeDCW ,

Thank you very much for your answer. As of today, we don't officially support the use of the AWS CPP SDK with Unreal Engine. (see the feature request for Unreal Support).

This also does seem like a different issue than the one reported above so I would suggest to open a new issue with all the details related to your case specifically the full behavior experienced and reproduction steps. I see that you have commented on this issue : https://github.com/aws/aws-sdk-cpp/issues/2513 Is the behavior you experienced similar to this?

As a side note: The aws-sdk-cpp port in vcpkg is kept up to date by Microsoft team members and community contributors. If you need any specific vcpkg support, please create an issue on the vcpkg repository. Best regards,

Yasmine

xyzmultimedia commented 9 months ago

Hi Yasmine,

Thank you for the help! I realized some time after posting as well that I was confused about how CMake builds the static libraries, so I now built the correct static libraries and copied those over to the directory (just .libs). I also put down the path to the .libs under Linker -> General -> Additional Library Directories.

My problem now is a linker issue. With code like below (just to test my setup), I see unresolved linker issues:

#define USE_IMPORT_EXPORT
#define USE_WINDOWS_DLL_SEMANTICS

#include <aws/core/Aws.h>
int main(int argc, char** argv)
{
    Aws::SDKOptions options;
    Aws::InitAPI(options);
    {
        // make your SDK calls here.
    }
    Aws::ShutdownAPI(options);
    return 0;
}

Results in: image

Additional Library Dependencies = (source code folder) Additional Dependencies = aws-cpp-sdk-core.lib;aws-c-auth.lib;aws-c-cal.lib;aws-c-common.lib;aws-c-compression.lib;aws-c-event-stream.lib;aws-checksums.lib;aws-c-http.lib;aws-c-io.lib;aws-c-mqtt.lib;aws-crt-cpp.lib;aws-c-s3.lib;aws-c-sdkutils.lib;aws-cpp-sdk-lambda.lib;%(AdditionalDependencies)

Thanks again for the help, slow and steady progress!