Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xyzmultimedia opened this issue Sep 13, 2023 · 10 comments
Labels
bug This issue is a bug. build-problem problems with building this sdk p3 This is a minor priority issue

Comments

@xyzmultimedia
Copy link

xyzmultimedia commented Sep 13, 2023

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

@xyzmultimedia xyzmultimedia added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 13, 2023
@yasminetalby yasminetalby removed the needs-triage This issue or PR still needs to be triaged. label Sep 18, 2023
@yasminetalby yasminetalby self-assigned this Sep 18, 2023
@yasminetalby
Copy link
Contributor

yasminetalby commented Sep 18, 2023

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

@yasminetalby yasminetalby added p2 This is a standard priority issue response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. p3 This is a minor priority issue and removed p2 This is a standard priority issue labels Sep 18, 2023
@github-actions
Copy link

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.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Sep 21, 2023
@xyzmultimedia
Copy link
Author

xyzmultimedia commented Sep 24, 2023

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

@github-actions github-actions bot removed closing-soon This issue will automatically close in 4 days unless further comments are made. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. labels Sep 25, 2023
@JakeDCW
Copy link

JakeDCW commented Oct 2, 2023

I am also experiencing the same issue as this.

@yasminetalby
Copy link
Contributor

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
Copy link
Contributor

Hello @JakeDCW ,

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

  • What steps are you taking to build the SDK?
  • What environment are you in?
  • What is the exact behavior you are witnessing?

Best regards

@yasminetalby yasminetalby added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. label Oct 2, 2023
@JakeDCW
Copy link

JakeDCW commented Oct 3, 2023

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.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. label Oct 4, 2023
@yasminetalby
Copy link
Contributor

yasminetalby commented Oct 4, 2023

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 : #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
Copy link
Author

xyzmultimedia commented Oct 10, 2023

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!

@peted70
Copy link

peted70 commented Nov 16, 2024

I have the exact same issue as the original poster.
i.e. access violation here
clientConfig.region = Aws::String("us-east-2"); // xstring's Memmove failure

Did anyone find a fix?
Not too sure how updating the nuget packages helps with this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. build-problem problems with building this sdk p3 This is a minor priority issue
Projects
None yet
Development

No branches or pull requests

5 participants