2022-12-20 11:23:09 -05:00
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
2024-01-16 10:41:11 -05:00
2022-12-20 11:23:09 -05:00
/**
* 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.list_tables.inc]
# include <aws/core/Aws.h>
2022-12-20 11:23:09 -05:00
# include <aws/core/utils/Outcome.h>
2021-12-02 15:10:47 -05:00
# include <aws/dynamodb/DynamoDBClient.h>
# include <aws/dynamodb/model/ListTablesRequest.h>
# include <aws/dynamodb/model/ListTablesResult.h>
# include <iostream>
// snippet-end:[dynamodb.cpp.list_tables.inc]
2022-12-20 11:23:09 -05:00
# include "dynamodb_samples.h"
2021-12-02 15:10:47 -05:00
2022-12-20 11:23:09 -05:00
// snippet-start:[dynamodb.cpp.list_tables.code]
//! List the Amazon DynamoDB tables for the current AWS account.
/*!
\sa listTables()
\param clientConfiguration: AWS client configuration.
\return bool: Function succeeded.
*/
2021-12-02 15:10:47 -05:00
2022-12-20 11:23:09 -05:00
bool AwsDoc : : DynamoDB : : listTables (
const Aws : : Client : : ClientConfiguration & clientConfiguration ) {
Aws : : DynamoDB : : DynamoDBClient dynamoClient ( clientConfiguration ) ;
Aws : : DynamoDB : : Model : : ListTablesRequest listTablesRequest ;
listTablesRequest . SetLimit ( 50 ) ;
do {
const Aws : : DynamoDB : : Model : : ListTablesOutcome & outcome = dynamoClient . ListTables (
listTablesRequest ) ;
if ( ! outcome . IsSuccess ( ) ) {
std : : cout < < " Error: " < < outcome . GetError ( ) . GetMessage ( ) < < std : : endl ;
return false ;
}
for ( const auto & tableName : outcome . GetResult ( ) . GetTableNames ( ) )
std : : cout < < tableName < < std : : endl ;
listTablesRequest . SetExclusiveStartTableName (
outcome . GetResult ( ) . GetLastEvaluatedTableName ( ) ) ;
2021-12-02 15:10:47 -05:00
2022-12-20 11:23:09 -05:00
} while ( ! listTablesRequest . GetExclusiveStartTableName ( ) . empty ( ) ) ;
2021-12-02 15:10:47 -05:00
2022-12-20 11:23:09 -05:00
return true ;
}
// snippet-end:[dynamodb.cpp.list_tables.code]
/*
* main function
*
* Usage: 'run_list_tables'
*
*/
# ifndef TESTING_BUILD
int main ( int argc , char * * argv ) {
2021-12-02 15:10:47 -05:00
std : : cout < < " Your DynamoDB Tables: " < < std : : endl ;
Aws : : SDKOptions options ;
Aws : : InitAPI ( options ) ;
{
Aws : : Client : : ClientConfiguration clientConfig ;
2022-12-20 11:23:09 -05:00
// Optional: Set to the AWS Region (overrides config file).
// clientConfig.region = "us-east-1";
2021-12-02 15:10:47 -05:00
2022-12-20 11:23:09 -05:00
AwsDoc : : DynamoDB : : listTables ( clientConfig ) ;
2021-12-02 15:10:47 -05:00
}
Aws : : ShutdownAPI ( options ) ;
return 0 ;
2022-12-20 11:23:09 -05:00
}
# endif // TESTING_BUILD