Skip to content

Commit

Permalink
Merge pull request #3 from awsdocs/master
Browse files Browse the repository at this point in the history
Getting update from awsdocs
  • Loading branch information
jschwarzwalder authored Jun 8, 2018
2 parents cd3b640 + be9a224 commit f72e4e6
Show file tree
Hide file tree
Showing 21 changed files with 808 additions and 25 deletions.
1 change: 1 addition & 0 deletions cpp/example_code/dynamodb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ project(dynamodb-examples)
find_package(aws-sdk-cpp)

set(EXAMPLES "")
list(APPEND EXAMPLES "batch_get_item")
list(APPEND EXAMPLES "create_table")
list(APPEND EXAMPLES "create_table_composite_key")
list(APPEND EXAMPLES "delete_item")
Expand Down
127 changes: 127 additions & 0 deletions cpp/example_code/dynamodb/batch_get_item.cpp
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;
}
2 changes: 1 addition & 1 deletion go/example_code/cloudtrail/describe_trails.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func main() {
os.Exit(1)
}

fmt.Println("Found",len(resp.TrailList),"trail(s) in", regionName)
fmt.Println("Found",len(resp.TrailList),"trail(s) in", "us-west-2")
fmt.Println("")

for _, trail := range resp.TrailList {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static void main(String[] args)

RunInstancesResult run_response = ec2.runInstances(run_request);

String instance_id = run_response.getReservation().getReservationId();
String reservation_id = run_response.getReservation().getReservationId();

Tag tag = new Tag()
.withKey("Name")
Expand All @@ -64,7 +64,7 @@ public static void main(String[] args)

System.out.printf(
"Successfully started EC2 instance %s based on AMI %s",
instance_id, ami_id);
reservation_id, ami_id);
}
}

34 changes: 22 additions & 12 deletions javascript/example_code/cognito/cognito_getcreds.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
<!-- 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 BROWSER 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/browser-cognito-browser-creds.html
-->
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Amazon Cognito Credenials Example</title>
<meta charset="utf-8">
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.213.1.min.js"></script>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.244.1.min.js"></script>

</head>

<body>
<div id="results">data</div>
<script type="application/javascript">
// Initialize the Amazon Cognito credentials provider
AWS.config.region = 'REGION'; // Region
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'IDENTITY_POOL_ID',
});
<div id="results">data</div>
<script type="application/javascript">
// Set your needed values
var IDENTITY_POOL_ID = 'Your Cognito identity pool ID';
var ACCOUNT_ID = 'Your AWS account ID';
var REGION = 'Your AWS region';


// Initialize the Amazon Cognito credentials provider
AWS.config.region = REGION; // Region
AWS.config.credentials = new AWS.CognitoIdentityCredentials({IdentityPoolId: IDENTITY_POOL_ID,});


var getIdParams = {
IdentityPoolId: 'IDENTITY_POOL_ID',
AccountId: 'AWS_ACCOUNT_ID'
IdentityPoolId: IDENTITY_POOL_ID,
AccountId: AWS_ACCOUNT_ID
};

var cognitoidentity = new AWS.CognitoIdentity({apiVersion: '2014-06-30'});
Expand All @@ -29,9 +39,9 @@
if (err) {
results.innerHTML = "Error" + err;
} else {
results.innerHTML = "Cognito Identity ID is " + data.IdentityId;
results.innerHTML = "Cognito Identity ID is " + data.IdentityId;
}
});
</script>
</script>
</body>
</html>
30 changes: 30 additions & 0 deletions javascript/example_code/mediaconvert/emc_canceljob.js
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);
}
);
Loading

0 comments on commit f72e4e6

Please sign in to comment.