[Lumberyard 1.11.1.0] Simple example create DynamoDB Client in C++?

Hi, i trying create DynamoDB Client in C++, i have IAM user customized for DynamoDB (ID and Secret Key). And i want understand how correctly create DynamoDB Clien in c++.

I Try


Aws::Client::ClientConfiguration clientConfiguration;
clientConfiguration.region = "us-west-2";
Aws::DynamoDB::DynamoDBClient* dynamoDBClient = nullptr;
dynamoDBClient = new Aws::DynamoDB::DynamoDBClient(Aws::Auth::AWSCredentials(IDKey, SecretKey), clientConfiguration);

After i try build solution i see many errors “error LNK2019: unresolved external symbol” and i think problem not in missing header files. Will be nice see very simple code how correctly create DynamoDB Client and simple access to data of DB :slight_smile:

edit:1
Forgot add to “wscript” uselib = [‘AWS_CPP_SDK_GAMELIFT’] on this moment compiled all good, but can create correct request (create tablet) and i’m not sure is connected successfully.

[Example]

  1. Create AIM user and customize hi to DynamoDB

  2. Add to game project “Cloud Canvas Gem

  3. In “wscript” add

win_debug_dedicated_uselib = ['AWS_CPP_SDK_ALL'],
win_profile_dedicated_uselib = ['AWS_CPP_SDK_ALL'],
win_performance_dedicated_uselib = ['AWS_CPP_SDK_ALL'],
win_release_dedicated_uselib = ['AWS_CPP_SDK_ALL'],

I think this better because if Client have access to DB it’s bad idea. Only server must have access to DB.

  1. In c++

#include <aws/core/auth/AWSCredentialsProvider.h>
#include <aws/dynamodb/model/CreateTableRequest.h>
#include <aws/dynamodb/model/CreateTableResult.h>
#include <aws/dynamodb/model/AttributeDefinition.h>
#include <aws/dynamodb/model/ScalarAttributeType.h>
#include <aws/dynamodb/DynamoDBClient.h>
#include <aws/core/utils/Outcome.h>
..................
Aws::String DynamoDB_IDKey = "***"; //<< Id key
Aws::String DynamoDB_SecretKey = "***"; //<< Secret key
// create DynamoDB Client
Aws::Client::ClientConfiguration clientConfiguration;
clientConfiguration.region = "us-west-2";
clientConfiguration.endpointOverride = "dynamodb.us-west-2.amazonaws.com";
Aws::DynamoDB::DynamoDBClient* DynamoDBClient = nullptr;
DynamoDBClient = new Aws::DynamoDB::DynamoDBClient(Aws::Auth::AWSCredentials(DynamoDB_IDKey, DynamoDB_SecretKey), clientConfiguration);
if (DynamoDBClient)
{
// create request, in example create tablet
Aws::DynamoDB::Model::CreateTableRequest request;
request.SetTableName("MusicCollection");<br>
Aws::DynamoDB::Model::AttributeDefinition attr;
attr.SetAttributeName("Artist");
attr.SetAttributeType(Aws::DynamoDB::Model::ScalarAttributeType::S);
request.AddAttributeDefinitions(attr);
Aws::DynamoDB::Model::KeySchemaElement keyShema;
keyShema.SetAttributeName("Artist");
keyShema.SetKeyType(Aws::DynamoDB::Model::KeyType::HASH);
request.AddKeySchema(keyShema);
Aws::DynamoDB::Model::ProvisionedThroughput pt;
pt.SetReadCapacityUnits(5);
pt.SetWriteCapacityUnits(5);
request.SetProvisionedThroughput(pt);
DynamoDBClient->CreateTable(request); // Send request }
.......................

Nice! Thanks for sharing @Anatoliy :smiley: