-
Notifications
You must be signed in to change notification settings - Fork 4
/
describe_table.cpp
executable file
·94 lines (80 loc) · 3.66 KB
/
describe_table.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//snippet-sourcedescription:[describe_table.cpp demonstrates how to retrieve information about an Amazon DynamoDB table.]
//snippet-keyword:[AWS SDK for C++]
//snippet-keyword:[Code Sample]
//snippet-service:[Amazon DynamoDB]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[11/30/2021]
//snippet-sourceauthor:[scmacdon - aws]
/*
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
//snippet-start:[dynamodb.cpp.describe_table.inc]
#include <aws/core/Aws.h>
#include <aws/core/utils/Outcome.h>
#include <aws/dynamodb/DynamoDBClient.h>
#include <aws/dynamodb/model/DescribeTableRequest.h>
#include <iostream>
//snippet-end:[dynamodb.cpp.describe_table.inc]
/*
Get information about (describe) a DynamoDB table.
To run this C++ code example, ensure that you have setup your development environment, including your credentials.
For information, see this documentation topic:
https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/getting-started.html
*/
int main(int argc, char** argv)
{
const Aws::String USAGE =
"Usage:\n"
" run_describe_table <region> <table>\n"
"Where:\n"
" region - region.\n"
" table - the table to describe.\n"
"Examples:\n"
" run_describe_table ap-northeast-1 Music\n";
if (argc < 3)
{
std::cout << USAGE;
return 1;
}
Aws::SDKOptions options;
Aws::InitAPI(options);
{
const Aws::String table = (argv[2]);
const Aws::String region = (argv[1]); //"eu-west-1";
// snippet-start:[dynamodb.cpp.describe_table.code]
Aws::Client::ClientConfiguration clientConfig;
if (!region.empty())
clientConfig.region = region;
Aws::DynamoDB::DynamoDBClient dynamoClient(clientConfig);
Aws::DynamoDB::Model::DescribeTableRequest dtr;
dtr.SetTableName(table);
const Aws::DynamoDB::Model::DescribeTableOutcome& result = dynamoClient.DescribeTable(dtr);
if (result.IsSuccess())
{
const Aws::DynamoDB::Model::TableDescription& td = result.GetResult().GetTable();
std::cout << "Table name : " << td.GetTableName() << std::endl;
std::cout << "Table ARN : " << td.GetTableArn() << std::endl;
std::cout << "Status : " << Aws::DynamoDB::Model::TableStatusMapper::GetNameForTableStatus(td.GetTableStatus()) << std::endl;
std::cout << "Item count : " << td.GetItemCount() << std::endl;
std::cout << "Size (bytes): " << td.GetTableSizeBytes() << std::endl;
const Aws::DynamoDB::Model::ProvisionedThroughputDescription& ptd = td.GetProvisionedThroughput();
std::cout << "Throughput" << std::endl;
std::cout << " Read Capacity : " << ptd.GetReadCapacityUnits() << std::endl;
std::cout << " Write Capacity: " << ptd.GetWriteCapacityUnits() << std::endl;
const Aws::Vector<Aws::DynamoDB::Model::AttributeDefinition>& ad = td.GetAttributeDefinitions();
std::cout << "Attributes" << std::endl;
for (const auto& a : ad)
std::cout << " " << a.GetAttributeName() << " (" <<
Aws::DynamoDB::Model::ScalarAttributeTypeMapper::GetNameForScalarAttributeType(a.GetAttributeType()) <<
")" << std::endl;
}
else
{
std::cout << "Failed to describe table: " << result.GetError().GetMessage();
}
// snippet-end:[dynamodb.cpp.describe_table.code]
}
Aws::ShutdownAPI(options);
return 0;
}