I am developing a public (ie insecure) client application in c++.
This is intended to allow the user to login as the first step to ultimately access S3, dynamoDB and potentially other resources.
It is being tested on a client without the CLI - effectively the setup expected in the production environment
Windows 11
aws-sdk-cpp,1.11.285
The SDK is built using vcpkg:-
vcpkg install aws-sdk-cpp[cognito-identity,cognito-idp,core,dynamodb,s3]
However the constructor is taking at least 30s to return - as it has numerous extendedtimeouts with failed attempts - which appear to be failures to connect to an EC2 metadata service.
The following is a minimum replication.
The log is: https://drive.google.com/file/d/1A4RvEoXNgOiEHwVYYPq_whu5wUAIsygh/view?usp=sharing
The full source file is: https://drive.google.com/file/d/1GNxjeGBrRoBSh2jMmjcwnJCN2sA05inF/view?usp=sharing
I have an additional problem that it's not retrieving tokens after authentication, but since I'm not sure if this contruction issue is contributing I'm asking about the timeout problem first.
class CognitoManager {
private:
Aws::CognitoIdentityProvider::CognitoIdentityProviderClient cognitoClient;
public:
CognitoManager() {
Aws::Client::ClientConfiguration clientConfig;
clientConfig.region = "eu-west-2";
// Initialize the Cognito client with anonymous credentials for initiating public operations
auto credentialsProvider = Aws::MakeShared<Aws::Auth::AnonymousAWSCredentialsProvider>("AnonymousProvider");
cognitoClient = Aws::CognitoIdentityProvider::CognitoIdentityProviderClient(credentialsProvider, clientConfig);
}
~CognitoManager() {
}
}
int main() {
std::cout << "Hello World!\n";
Aws::SDKOptions options;
options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Trace; // More detailed logging
const char* logFileName = "c:\\src\\aws_sdk_helloCognito_";
// or Aws::Utils::Logging::LogLevel::Debug
options.loggingOptions.logger_create_fn = [=] {
return Aws::MakeShared<Aws::Utils::Logging::DefaultLogSystem>("LOG_TAG", Aws::Utils::Logging::LogLevel::Trace, logFileName);
};
std::cout << "Initializing AWS SDK..." << std::endl;
Aws::InitAPI(options);
std::cout << "AWS SDK initialized." << std::endl;
std::cout << "constructing CognitoManager" << std::endl;
CognitoManager manager;
std::cout << "CognitoManager constructed" << std::endl;
if (manager.Login("userPoolId", "clientId", "userName", "userPassword")) {
std::cout << "Login successful for helloCognito" << std::endl;
}
std::cout << "Shutting down AWS SDK..." << std::endl;
Aws::ShutdownAPI(options);
std::cout << "AWS SDK shut down." << std::endl;
std::cin.get(); // wait for user input to view the console output
return 0;
}