-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from awsdocs/master
Getting update from awsdocs
- Loading branch information
Showing
21 changed files
with
808 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
// BatchGetItem.cpp : Defines the entry point for the console application. | ||
// | ||
#include <aws/core/Aws.h> | ||
#include <aws/core/utils/Outcome.h> | ||
#include <aws/dynamodb/DynamoDBClient.h> | ||
#include <aws/dynamodb/model/AttributeDefinition.h> | ||
#include <aws/dynamodb/model/BatchGetItemRequest.h> | ||
#include <aws/dynamodb/model/KeysAndAttributes.h> | ||
#include <aws/core/http/HttpRequest.h> | ||
#include <iostream> | ||
|
||
|
||
/** | ||
* Batch get items from different DynamoDB tables. | ||
* | ||
* Sample data and loading instructions can be found at: | ||
* https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SampleData.html | ||
* | ||
* This code expects that you have AWS credentials set up per: | ||
* http://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/credentials.html | ||
*/ | ||
int main(int argc, char** argv) | ||
{ | ||
Aws::SDKOptions options; | ||
|
||
Aws::InitAPI(options); | ||
{ | ||
Aws::Client::ClientConfiguration clientConfig; | ||
// Set the region where your DynamoDB tables exist | ||
clientConfig.region = Aws::Region::US_WEST_2; | ||
Aws::DynamoDB::DynamoDBClient dynamoClient(clientConfig); | ||
|
||
Aws::DynamoDB::Model::BatchGetItemRequest req; | ||
|
||
// Table1: Forum | ||
Aws::String t1Name = "Forum"; | ||
Aws::DynamoDB::Model::KeysAndAttributes t1KeyAttrs; | ||
//Table1: Projection expression | ||
t1KeyAttrs.SetProjectionExpression("#n, Category, Messages, #v"); | ||
|
||
// Table1: Expression attribute names | ||
Aws::Http::HeaderValueCollection hvc; | ||
hvc.emplace("#n", "Name"); | ||
hvc.emplace("#v", "Views"); | ||
t1KeyAttrs.SetExpressionAttributeNames(hvc); | ||
|
||
// Table1: Set key name, type and value to search | ||
// | ||
// Since we are searching for two possible values of "Name", | ||
// we have to use to separate key maps | ||
// | ||
// Name = "Amazon DynamoDB" | ||
Aws::Map<Aws::String, Aws::DynamoDB::Model::AttributeValue> t1KeysA; | ||
Aws::DynamoDB::Model::AttributeValue t1key1; | ||
t1key1.SetS("Amazon DynamoDB"); | ||
t1KeysA.emplace("Name", t1key1); | ||
t1KeyAttrs.AddKeys(t1KeysA); | ||
|
||
// Name = "Amazon S3" | ||
Aws::Map<Aws::String, Aws::DynamoDB::Model::AttributeValue> t1KeysB; | ||
Aws::DynamoDB::Model::AttributeValue t1key2; | ||
t1key2.SetS("Amazon S3"); | ||
t1KeysB.emplace("Name", t1key2); | ||
t1KeyAttrs.AddKeys(t1KeysB); | ||
req.AddRequestItems(t1Name, t1KeyAttrs); | ||
|
||
// Table2: ProductCatalog | ||
Aws::String t2Name = "ProductCatalog"; | ||
Aws::DynamoDB::Model::KeysAndAttributes t2KeyAttrs; | ||
//Table2: Projection expression | ||
t1KeyAttrs.SetProjectionExpression("Title, Price, Color"); | ||
|
||
// Table2: Set key name, type and value to search | ||
// | ||
// Name = "Id", value = 201 | ||
Aws::Map<Aws::String, Aws::DynamoDB::Model::AttributeValue> t2KeysA; | ||
Aws::DynamoDB::Model::AttributeValue t2key1; | ||
t2key1.SetN("201"); | ||
t2KeysA.emplace("Id", t2key1); | ||
t2KeyAttrs.AddKeys(t2KeysA); | ||
req.AddRequestItems(t2Name, t2KeyAttrs); | ||
|
||
const Aws::DynamoDB::Model::BatchGetItemOutcome& result = dynamoClient.BatchGetItem(req); | ||
|
||
if (result.IsSuccess()) | ||
{ | ||
for(const auto& var : result.GetResult().GetResponses()) | ||
{ | ||
Aws::String tableName = var.first; | ||
std::cout << tableName << std::endl; | ||
if (tableName == "Forum") | ||
{ | ||
std::cout << "Name | Category | Message | Views" << std::endl; | ||
for (const auto& itm : var.second) | ||
{ | ||
std::cout << itm.at("Name").GetS() << " | "; | ||
std::cout << itm.at("Category").GetS() << " | "; | ||
std::cout << (itm.count("Message") == 0 ? "" : itm.at("Messages").GetN()) << " | "; | ||
std::cout << (itm.count("Views") == 0 ? "" : itm.at("Views").GetN()) << std::endl; | ||
} | ||
} | ||
else | ||
{ | ||
std::cout << "Title | Price | Color" << std::endl; | ||
for (const auto& itm : var.second) | ||
{ | ||
std::cout << itm.at("Title").GetS() << " | "; | ||
std::cout << (itm.count("Price") == 0 ? "" : itm.at("Price").GetN()); | ||
if (itm.count("Color")) | ||
{ | ||
std::wcout << " | "; | ||
for (const auto& litm : itm.at("Color").GetL()) | ||
std::cout << litm->GetS() << " "; | ||
} | ||
std::wcout << std::endl; | ||
} | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
std::cout << "Batch get item failed: " << result.GetError().GetMessage(); | ||
} | ||
} | ||
Aws::ShutdownAPI(options); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// Licensed under the Apache-2.0 License on an "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND. | ||
|
||
// ABOUT THIS NODE.JS SAMPLE: This sample is part of the SDK for JavaScript Developer Guide topic at | ||
// https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/emc-examples-jobs.html | ||
// Load the AWS SDK for Node.js | ||
var AWS = require('aws-sdk'); | ||
// Set the region | ||
AWS.config.update({region: 'us-west-2'}); | ||
// Set MediaConvert to customer endpoint | ||
AWS.config.mediaconvert = {endpoint : 'ACCOUNT_ENDPOINT'}; | ||
|
||
|
||
var params = { | ||
Id: 'JOB_ID' /* required */ | ||
}; | ||
|
||
|
||
// Create a promise on a MediaConvert object | ||
var endpointPromise = new AWS.MediaConvert({apiVersion: '2017-08-29'}).cancelJob(params).promise(); | ||
|
||
// Handle promise's fulfilled/rejected status | ||
endpointPromise.then( | ||
function(data) { | ||
console.log("Job " + params.Id + " is canceled"); | ||
}, | ||
function(err) { | ||
console.log("Error", err); | ||
} | ||
); |
Oops, something went wrong.