SIGN IN SIGN UP

Welcome to the AWS Code Examples Repository. This repo contains code examples used in the AWS documentation, AWS SDK Developer Guides, and more. For more information, see the Readme.md file below.

0 0 1 Java
2021-12-02 15:10:47 -05:00
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/**
* Before running this C++ code example, set up your development environment, including your credentials.
*
* For more information, see the following documentation topic:
*
* https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/getting-started.html
*
* For information on the structure of the code examples and how to build and run the examples, see
* https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/getting-started-code-examples.html.
*
**/
2021-12-02 15:10:47 -05:00
// snippet-start:[dynamodb.cpp.update_table.inc]
#include <aws/core/Aws.h>
#include <aws/core/utils/Outcome.h>
2021-12-02 15:10:47 -05:00
#include <aws/dynamodb/DynamoDBClient.h>
#include <aws/dynamodb/model/ProvisionedThroughput.h>
#include <aws/dynamodb/model/UpdateTableRequest.h>
#include <iostream>
// snippet-end:[dynamodb.cpp.update_table.inc]
#include "dynamodb_samples.h"
2021-12-02 15:10:47 -05:00
/**
* This example sets the provisioned throughput of an Amazon DynamoDB table.
*
* For information about provisioned throughput,
* see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadWriteCapacityMode.html.
*
*/
2021-12-02 15:10:47 -05:00
// snippet-start:[dynamodb.cpp.update_table.code]
//! Update a DynamoDB table.
/*!
\sa updateTable()
\param tableName: Name for the DynamoDB table.
\param readCapacity: Provisioned read capacity.
\param writeCapacity: Provisioned write capacity.
\param clientConfiguration: AWS client configuration.
\return bool: Function succeeded.
*/
bool AwsDoc::DynamoDB::updateTable(const Aws::String &tableName,
long long readCapacity, long long writeCapacity,
const Aws::Client::ClientConfiguration &clientConfiguration) {
Aws::DynamoDB::DynamoDBClient dynamoClient(clientConfiguration);
2021-12-02 15:10:47 -05:00
std::cout << "Updating " << tableName << " with new provisioned throughput values"
<< std::endl;
std::cout << "Read capacity : " << readCapacity << std::endl;
std::cout << "Write capacity: " << writeCapacity << std::endl;
2021-12-02 15:10:47 -05:00
Aws::DynamoDB::Model::UpdateTableRequest request;
Aws::DynamoDB::Model::ProvisionedThroughput provisionedThroughput;
provisionedThroughput.WithReadCapacityUnits(readCapacity).WithWriteCapacityUnits(
writeCapacity);
request.WithProvisionedThroughput(provisionedThroughput).WithTableName(tableName);
const Aws::DynamoDB::Model::UpdateTableOutcome &outcome = dynamoClient.UpdateTable(
request);
if (outcome.IsSuccess()) {
std::cout << "Successfully updated the table." << std::endl;
} else {
const Aws::DynamoDB::DynamoDBError &error = outcome.GetError();
if (error.GetErrorType() == Aws::DynamoDB::DynamoDBErrors::VALIDATION &&
error.GetMessage().find("The provisioned throughput for the table will not change") != std::string::npos) {
std::cout << "The provisioned throughput for the table will not change." << std::endl;
} else {
std::cerr << outcome.GetError().GetMessage() << std::endl;
return false;
}
}
return waitTableActive(tableName, dynamoClient);
}
// snippet-end:[dynamodb.cpp.update_table.code]
/*
*
* main function
*
* Usage: 'run_update_table <table> <read> <write>'
*
* Prerequisites: Create a DynamoDB table.
*
*/
#ifndef TESTING_BUILD
int main(int argc, char **argv) {
if (argc < 4) {
std::cout << R"(
Usage:
runupdate_table <table> <read> <write>
Where:
table - the table to put the item in.
read - the new read capacity of the table.
write - the new write capacity of the table.
)";
2021-12-02 15:10:47 -05:00
return 1;
}
Aws::SDKOptions options;
Aws::InitAPI(options);
{
const Aws::String tableName(argv[1]);
const long long readCapacity = Aws::Utils::StringUtils::ConvertToInt64(argv[2]);
const long long writeCapacity = Aws::Utils::StringUtils::ConvertToInt64(
argv[3]);
2021-12-02 15:10:47 -05:00
Aws::Client::ClientConfiguration clientConfig;
// Optional: Set to the AWS Region (overrides config file).
// clientConfig.region = "us-east-1";
2021-12-02 15:10:47 -05:00
AwsDoc::DynamoDB::updateTable(tableName, readCapacity, writeCapacity,
clientConfig);
2021-12-02 15:10:47 -05:00
}
Aws::ShutdownAPI(options);
return 0;
}
#endif // TESTING_BUILD