Skip to content

Commit 4c5489e

Browse files
authored
C++,Bash: Multi-service, update bucket names. (#6944)
1 parent a370cb2 commit 4c5489e

24 files changed

+146
-52
lines changed

.doc_gen/metadata/dynamodb_metadata.yaml

+28-2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ dynamodb_CreateTable:
8181
- description:
8282
snippet_tags:
8383
- dynamodb.cpp.create_table.code
84+
- description: Code that waits for the table to become active.
85+
snippet_tags:
86+
- cpp.example_code.dynamodb.scenario.waitTableActive
87+
8488
Go:
8589
versions:
8690
- sdk_version: 2
@@ -623,11 +627,13 @@ dynamodb_PutItem:
623627
versions:
624628
- sdk_version: 1
625629
github: cpp/example_code/dynamodb
626-
sdkguide:
627630
excerpts:
628631
- description:
629632
snippet_tags:
630633
- dynamodb.cpp.put_item.code
634+
- description: Code that waits for the table to become active.
635+
snippet_tags:
636+
- cpp.example_code.dynamodb.scenario.waitTableActive
631637
Go:
632638
versions:
633639
- sdk_version: 2
@@ -890,6 +896,9 @@ dynamodb_UpdateItem:
890896
- description:
891897
snippet_tags:
892898
- dynamodb.cpp.update_item.code
899+
- description: Code that waits for the table to become active.
900+
snippet_tags:
901+
- cpp.example_code.dynamodb.scenario.waitTableActive
893902
Go:
894903
versions:
895904
- sdk_version: 2
@@ -1109,11 +1118,13 @@ dynamodb_DeleteItem:
11091118
versions:
11101119
- sdk_version: 1
11111120
github: cpp/example_code/dynamodb
1112-
sdkguide:
11131121
excerpts:
11141122
- description:
11151123
snippet_tags:
11161124
- cpp.example_code.dynamodb.delete_item
1125+
- description: Code that waits for the table to become active.
1126+
snippet_tags:
1127+
- cpp.example_code.dynamodb.scenario.waitTableActive
11171128
Swift:
11181129
versions:
11191130
- sdk_version: 1
@@ -1774,6 +1785,21 @@ dynamodb_BatchExecuteStatement:
17741785
- cpp.example_code.dynamodb.BatchExecuteStatement.Delete
17751786
services:
17761787
dynamodb: {BatchExecuteStatement}
1788+
dynamodb_UpdateTable:
1789+
languages:
1790+
C++:
1791+
versions:
1792+
- sdk_version: 1
1793+
github: cpp/example_code/dynamodb
1794+
excerpts:
1795+
- description:
1796+
snippet_tags:
1797+
- dynamodb.cpp.update_table.code
1798+
- description: Code that waits for the table to become active.
1799+
snippet_tags:
1800+
- cpp.example_code.dynamodb.scenario.waitTableActive
1801+
services:
1802+
dynamodb: {UpdateTable}
17771803
dynamodb_Usage_DaxDemo:
17781804
title: Accelerate &DDB; reads with &DAX; using an &AWS; SDK
17791805
title_abbrev: Accelerate reads with &DAX;

aws-cli/bash-linux/s3/s3_getting_started.sh

+5-2
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ function s3_getting_started() {
5050
echo_repeat "*" 88
5151
echo "Welcome to the Amazon S3 getting started demo."
5252
echo_repeat "*" 88
53-
53+
echo "A unique bucket will be created by appending a Universally Unique Identifier to a bucket name prefix."
54+
echo -n "Enter a prefix for the S3 bucket that will be used in this demo: "
55+
get_input
56+
bucket_name_prefix=$get_input_result
5457
local bucket_name
55-
bucket_name=$(generate_random_name "amzn-s3-demo-bucket")
58+
bucket_name=$(generate_random_name "$bucket_name_prefix")
5659

5760
local region_code
5861
region_code=$(aws configure get region)

cpp/example_code/dynamodb/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Code excerpts that show you how to call individual service functions.
6767
- [Query](query_items.cpp#L22)
6868
- [Scan](scan_table.cpp#L23)
6969
- [UpdateItem](update_item.cpp#L24)
70+
- [UpdateTable](update_table.cpp#L33)
7071

7172
### Scenarios
7273

cpp/example_code/dynamodb/batch_write_item.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@ bool AwsDoc::DynamoDB::batchWriteItem(const Aws::String &jsonFilePath,
115115
std::cerr << "Error with DynamoDB::BatchWriteItem. "
116116
<< outcome.GetError().GetMessage()
117117
<< std::endl;
118+
return false;
118119
}
119120

120-
return true;
121+
return outcome.IsSuccess();
121122
}
122123

123124
//! Convert requests in JSON format to a vector of WriteRequest objects.

cpp/example_code/dynamodb/create_table.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ bool AwsDoc::DynamoDB::createTable(const Aws::String &tableName,
6868
else {
6969
std::cerr << "Failed to create table: " << outcome.GetError().GetMessage()
7070
<< std::endl;
71+
return false;
7172
}
7273

73-
return outcome.IsSuccess();
74+
return waitTableActive(tableName, dynamoClient);
7475
}
7576
// snippet-end:[dynamodb.cpp.create_table.code]
7677

cpp/example_code/dynamodb/create_table_composite_key.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ bool AwsDoc::DynamoDB::createTableWithCompositeKey(const Aws::String &tableName,
7979
else {
8080
std::cerr << "Failed to create table:" << outcome.GetError().GetMessage()
8181
<< std::endl;
82+
return false;
8283
}
8384

84-
return outcome.IsSuccess();
85+
return waitTableActive(tableName, dynamoClient);
8586
}
8687
// snippet-end:[dynamodb.cpp.create_table_composite_key.code]
8788

cpp/example_code/dynamodb/delete_item.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ bool AwsDoc::DynamoDB::deleteItem(const Aws::String &tableName,
5050
else {
5151
std::cerr << "Failed to delete item: " << outcome.GetError().GetMessage()
5252
<< std::endl;
53+
return false;
5354
}
5455

55-
return outcome.IsSuccess();
56+
return waitTableActive(tableName, dynamoClient);
5657
}
5758
// snippet-end:[cpp.example_code.dynamodb.delete_item]
5859

cpp/example_code/dynamodb/dynamodb_samples.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <aws/core/client/ClientConfiguration.h>
88
#include <aws/dynamodb/model/AttributeValue.h>
9+
#include <aws/dynamodb/DynamoDBClient.h>
910

1011
namespace AwsDoc {
1112
namespace DynamoDB {
@@ -262,11 +263,11 @@ namespace AwsDoc {
262263
/*!
263264
\sa waitTableActive()
264265
\param waitTableActive: The DynamoDB table's name.
265-
\param clientConfiguration: AWS client configuration.
266+
\param dynamoClient: A DynamoDB client.
266267
\return bool: Function succeeded.
267268
*/
268269
bool waitTableActive(const Aws::String &tableName,
269-
const Aws::Client::ClientConfiguration &clientConfiguration);
270+
const Aws::DynamoDB::DynamoDBClient &dynamoClient);
270271
//! Command line prompt/response utility function.
271272
/*!
272273
\\sa askQuestion()

cpp/example_code/dynamodb/dynamodb_utils.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ bool AwsDoc::DynamoDB::deleteMoviesDynamoDBTable(
146146
/*!
147147
\sa waitTableActive()
148148
\param waitTableActive: The DynamoDB table's name.
149-
\param clientConfiguration: AWS client configuration.
149+
\param dynamoClient: A DynamoDB client.
150150
\return bool: Function succeeded.
151151
*/
152152
bool AwsDoc::DynamoDB::waitTableActive(const Aws::String &tableName,
153-
const Aws::Client::ClientConfiguration &clientConfiguration) {
154-
Aws::DynamoDB::DynamoDBClient dynamoClient(clientConfiguration);
153+
const Aws::DynamoDB::DynamoDBClient &dynamoClient) {
154+
155155
// Repeatedly call DescribeTable until table is ACTIVE.
156156
const int MAX_QUERIES = 20;
157157
Aws::DynamoDB::Model::DescribeTableRequest request;

cpp/example_code/dynamodb/put_item.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ bool AwsDoc::DynamoDB::putItem(const Aws::String &tableName,
6969
}
7070
else {
7171
std::cerr << outcome.GetError().GetMessage() << std::endl;
72+
return false;
7273
}
7374

74-
return outcome.IsSuccess();
75+
return waitTableActive(tableName, dynamoClient);
7576
}
7677

7778
// snippet-end:[dynamodb.cpp.put_item.code]

cpp/example_code/dynamodb/update_item.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ bool AwsDoc::DynamoDB::updateItem(const Aws::String &tableName,
8080
request);
8181
if (outcome.IsSuccess()) {
8282
std::cout << "Item was updated" << std::endl;
83-
}
84-
else {
83+
} else {
8584
std::cerr << outcome.GetError().GetMessage() << std::endl;
85+
return false;
8686
}
8787

88-
return outcome.IsSuccess();
88+
return waitTableActive(tableName, dynamoClient);
8989
}
9090
// snippet-end:[dynamodb.cpp.update_item.code]
9191

cpp/example_code/dynamodb/update_table.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,18 @@ bool AwsDoc::DynamoDB::updateTable(const Aws::String &tableName,
6060
request);
6161
if (outcome.IsSuccess()) {
6262
std::cout << "Successfully updated the table." << std::endl;
63-
}
64-
else {
65-
std::cerr << outcome.GetError().GetMessage() << std::endl;
63+
} else {
64+
const Aws::DynamoDB::DynamoDBError &error = outcome.GetError();
65+
if (error.GetErrorType() == Aws::DynamoDB::DynamoDBErrors::VALIDATION &&
66+
error.GetMessage().find("The provisioned throughput for the table will not change") != std::string::npos) {
67+
std::cout << "The provisioned throughput for the table will not change." << std::endl;
68+
} else {
69+
std::cerr << outcome.GetError().GetMessage() << std::endl;
70+
return false;
71+
}
6672
}
6773

68-
return outcome.IsSuccess();
74+
return waitTableActive(tableName, dynamoClient);
6975
}
7076
// snippet-end:[dynamodb.cpp.update_table.code]
7177

cpp/example_code/s3/create_bucket.cpp

+17-5
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,39 @@ bool AwsDoc::S3::createBucket(const Aws::String &bucketName,
6060
*
6161
* main function
6262
*
63-
* Usage: 'run_create_bucket>'
63+
* Usage: 'run_create_bucket <bucket_name_prefix>
6464
*
6565
*/
6666

6767
#ifndef EXCLUDE_MAIN_FUNCTION
6868

69-
int main() {
69+
int main(int argc, char* argv[]) {
7070
Aws::SDKOptions options;
7171
InitAPI(options);
7272

73+
if (argc != 2) {
74+
std::cout << R"(
75+
Usage:
76+
run_create_bucket <bucket_name_prefix>
77+
Where:
78+
bucket_name - A bucket name prefix which will be made unique by appending a UUID.
79+
)" << std::endl;
80+
return 1;
81+
}
82+
83+
Aws::String bucketNamePrefix = argv[1];
84+
7385
{
7486
Aws::S3::S3ClientConfiguration clientConfig;
7587
// Optional: Set to the AWS Region in which the bucket was created (overrides config file).
7688
// clientConfig.region = "us-east-1";
7789

7890
// Create a unique bucket name to increase the chance of success
7991
// when trying to create the bucket.
80-
// Format: "amzn-s3-demo-bucket-" + lowercase UUID.
92+
// Format: "<bucketNamePrefix> + "-" + lowercase UUID.
8193
Aws::String uuid = Aws::Utils::UUID::RandomUUID();
82-
Aws::String bucketName = "amzn-s3-demo-bucket-" +
83-
Aws::Utils::StringUtils::ToLower(uuid.c_str());
94+
Aws::String bucketName = bucketNamePrefix + "-" +
95+
Aws::Utils::StringUtils::ToLower(uuid.c_str());
8496

8597
AwsDoc::S3::createBucket(bucketName, clientConfig);
8698
}

cpp/example_code/s3/list_objects_with_aws_global_region.cpp

+20-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <thread>
55
#include <iostream>
66
#include <aws/core/Aws.h>
7-
#include <aws/core/utils/logging/LogLevel.h>
87
#include <aws/core/client/ClientConfiguration.h>
98
#include <aws/s3/S3Client.h>
109
#include <aws/s3/model/CreateBucketRequest.h>
@@ -42,10 +41,10 @@
4241
*/
4342
static const int MAX_TIMEOUT_RETRIES = 20;
4443

45-
static Aws::String createOneBucket(const Aws::S3::S3Client &s3Client) {
44+
static Aws::String createOneBucket(const Aws::String &bucketNamePrefix, const Aws::S3::S3Client &s3Client) {
4645
// Create an S3 bucket within the us-west-2 AWS Region.
4746
Aws::String uuid = Aws::Utils::UUID::RandomUUID();
48-
Aws::String bucketName = "amzn-s3-demo-bucket-" +
47+
Aws::String bucketName = bucketNamePrefix +
4948
Aws::Utils::StringUtils::ToLower(uuid.c_str());
5049

5150
Aws::S3::Model::CreateBucketRequest createBucketRequest;
@@ -160,13 +159,14 @@ bool deleteABucket(const Aws::S3::S3Client &s3Client, const Aws::String &bucketN
160159
*/
161160

162161
bool AwsDoc::S3::listObjectsWithAwsGlobalRegion(
162+
const Aws::String &bucketNamePrefix,
163163
const Aws::S3::S3ClientConfiguration &clientConfig) {
164164
Aws::S3::S3ClientConfiguration config(clientConfig);
165165
config.region = Aws::Region::AWS_GLOBAL;
166166

167167
Aws::S3::S3Client s3Client(config);
168168

169-
Aws::String bucketName = createOneBucket(s3Client);
169+
Aws::String bucketName = createOneBucket(bucketNamePrefix, s3Client);
170170
if (bucketName.empty()) {
171171
return false;
172172
}
@@ -186,17 +186,31 @@ bool AwsDoc::S3::listObjectsWithAwsGlobalRegion(
186186
*
187187
* main function
188188
*
189+
* Usage: ' run_list_objects_with_aws_global_region_bucket <bucket_name_prefix>'
190+
*
189191
*/
190192

191193
#ifndef EXCLUDE_MAIN_FUNCTION
192194

193-
int main() {
195+
int main(int argc, char *argv[]) {
196+
if (argc != 2) {
197+
std::cout << R"(
198+
Usage:
199+
run_list_objects_with_aws_global_region_bucket <bucket_name_prefix>
200+
Where:
201+
bucket_name - A bucket name prefix which will be made unique by appending a UUID.
202+
)" << std::endl;
203+
return 1;
204+
}
205+
194206
Aws::SDKOptions options;
195207

196208
InitAPI(options);
209+
210+
Aws::String bucketNamePrefix = argv[1];
197211
{
198212
Aws::S3::S3ClientConfiguration config;
199-
AwsDoc::S3::listObjectsWithAwsGlobalRegion(config);
213+
AwsDoc::S3::listObjectsWithAwsGlobalRegion(bucketNamePrefix, config);
200214
}
201215
ShutdownAPI(options);
202216

cpp/example_code/s3/s3_examples.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ namespace AwsDoc {
6262
const Aws::S3::S3ClientConfiguration &clientConfig);
6363

6464
bool listObjectsWithAwsGlobalRegion(
65+
const Aws::String &bucketNamePrefix,
6566
const Aws::S3::S3ClientConfiguration &clientConfig);
6667

6768
Aws::String generatePreSignedPutObjectUrl(const Aws::String &bucketName,
@@ -107,7 +108,8 @@ namespace AwsDoc {
107108
const Aws::String &errorPage,
108109
const Aws::S3::S3ClientConfiguration &clientConfig);
109110

110-
bool S3_GettingStartedScenario(const Aws::String &uploadFilePath,
111+
bool S3_GettingStartedScenario(const Aws::String &bucketNamePrefix,
112+
const Aws::String &uploadFilePath,
111113
const Aws::String &saveFilePath,
112114
const Aws::Client::ClientConfiguration &clientConfig);
113115

0 commit comments

Comments
 (0)