Amazon Aurora DSQL is provided as a Preview service.
To learn more, see Betas and Previews
Use the C++ SDK to generate a token in Aurora DSQL
Once your cluster is ACTIVE
, you can generate an authentication token.
There are two ways to generate the token
-
If you are connecting as
admin
user, you use theGenerateDBConnectAdminAuthToken
-
If you are connecting with a custom database role, you use the
GenerateDBConnectAuthToken
The following example uses the following attributes to generate an authentication token for the admin role.
-
yourClusterEndpoint – endpoint of the cluster. Follows the format
your_cluster_identifier
.dsql.AWS_REGION
.on.aws -
region – The AWS Region, such as us-east-2 or us-east-1
#include <aws/core/Aws.h>
#include <aws/dsql/DSQLClient.h>
#include <iostream>
using namespace Aws;
using namespace Aws::DSQL;
std::string generateToken(String yourClusterEndpoint, String region) {
Aws::SDKOptions options;
Aws::InitAPI(options);
DSQLClientConfiguration clientConfig;
clientConfig.region = region;
DSQLClient client{clientConfig};
std::string token = "";
// If you aren not using admin role to connect, use GenerateDBConnectAuthToken instead
const auto presignedString = client.GenerateDBConnectAdminAuthToken(yourClusterEndpoint, region);
if (presignedString.IsSuccess()) {
token = presignedString.GetResult();
} else {
std::cerr << "Token generation failed." << std::endl;
}
std::cout << token << std::endl;
Aws::ShutdownAPI(options);
return token;
}