0
votes
  1. What would be an example on how to perform a query in AWS DynamoDB using the C++ SDK? I cannot find such an example in TableOperationTest.cpp in "aws-cpp-sdk-dynamodb-integration-tests".

  2. When I use "getItemRequest" to use a hash key to get an item result from DynamoDB, how to can I get the "key value" for the non-hash key?

For example, I have created a dynamo table as follows. "id" is the hash key.

{ "id": "1", "Status": "0", }

getItemRequest.AddKey("id", "1");
getItemRequest.SetTableName("mytablename");
auto getItemOutcome = dynamoDbClient.GetItem(getItemRequest);
GetItemResult result = getItemOutcome.GetResult();
Aws::Map<Aws::String, AttributeValue> returnedItemCollection = result.GetItem();
std::cout << "Status: " << returnedItemCollection["Status"].GetS() << std::endl;

I need to specify the key "Status" to get attribute value using returnedItemCollection["Status"].GetS(). How can I know the item has a key "Status"?

1
Do you want to know what keys are available ahead of time, as you are writing the code? Or do you want to know the keys dynamically after you have retrieved an item from the DB?Mark B
Thanks. I would like to know the keys dynamically after I have retrieved an item from the DB.iKanchi

1 Answers

1
votes

Do you mean, how can you know what keys are in the result? Perhaps I misunderstand the question, but isn't as simple as this?

for(auto& itemEntry : returnedItemCollection)
{
   std::cout << itemEntry.first << ": " << itemEntry.second.GetS() << std::endl;
}