Skip to content

Commit 80d9dea

Browse files
authored
Bash: Default to on-demand tables in DynamoDB examples. (#7268)
* Bash changing create table to use on-demand billing. * Update README.md
1 parent 508f6dd commit 80d9dea

File tree

5 files changed

+23
-34
lines changed

5 files changed

+23
-34
lines changed

aws-cli/.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* text=auto
2+
*.sh text eol=lf

aws-cli/bash-linux/dynamodb/README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ Code examples that show you how to perform the essential operations within a ser
4040

4141
Code excerpts that show you how to call individual service functions.
4242

43-
- [BatchGetItem](dynamodb_operations.sh#L902)
44-
- [BatchWriteItem](dynamodb_operations.sh#L834)
43+
- [BatchGetItem](dynamodb_operations.sh#L892)
44+
- [BatchWriteItem](dynamodb_operations.sh#L824)
4545
- [CreateTable](dynamodb_operations.sh#L17)
46-
- [DeleteItem](dynamodb_operations.sh#L535)
47-
- [DeleteTable](dynamodb_operations.sh#L998)
48-
- [DescribeTable](dynamodb_operations.sh#L183)
49-
- [GetItem](dynamodb_operations.sh#L439)
50-
- [ListTables](dynamodb_operations.sh#L969)
51-
- [PutItem](dynamodb_operations.sh#L257)
52-
- [Query](dynamodb_operations.sh#L614)
53-
- [Scan](dynamodb_operations.sh#L724)
54-
- [UpdateItem](dynamodb_operations.sh#L338)
46+
- [DeleteItem](dynamodb_operations.sh#L525)
47+
- [DeleteTable](dynamodb_operations.sh#L988)
48+
- [DescribeTable](dynamodb_operations.sh#L173)
49+
- [GetItem](dynamodb_operations.sh#L429)
50+
- [ListTables](dynamodb_operations.sh#L959)
51+
- [PutItem](dynamodb_operations.sh#L247)
52+
- [Query](dynamodb_operations.sh#L604)
53+
- [Scan](dynamodb_operations.sh#L714)
54+
- [UpdateItem](dynamodb_operations.sh#L328)
5555

5656

5757
<!--custom.examples.start-->
@@ -111,4 +111,4 @@ in the `aws-cli` folder.
111111

112112
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
113113

114-
SPDX-License-Identifier: Apache-2.0
114+
SPDX-License-Identifier: Apache-2.0

aws-cli/bash-linux/dynamodb/dynamodb_operations.sh

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
# SPDX-License-Identifier: Apache-2.0
3+
# SPDX-License-Identifier: Apache-2.0
44

55
###############################################################################
66
#
@@ -24,36 +24,33 @@ source ./awsdocs_general.sh
2424
# -n table_name -- The name of the table to create.
2525
# -a attribute_definitions -- JSON file path of a list of attributes and their types.
2626
# -k key_schema -- JSON file path of a list of attributes and their key types.
27-
# -p provisioned_throughput -- Provisioned throughput settings for the table.
2827
#
2928
# Returns:
3029
# 0 - If successful.
3130
# 1 - If it fails.
3231
###############################################################################
3332
function dynamodb_create_table() {
34-
local table_name attribute_definitions key_schema provisioned_throughput response
33+
local table_name attribute_definitions key_schema response
3534
local option OPTARG # Required to use getopts command in a function.
3635

3736
#######################################
3837
# Function usage explanation
3938
#######################################
4039
function usage() {
4140
echo "function dynamodb_create_table"
42-
echo "Creates an Amazon DynamoDB table."
41+
echo "Creates an Amazon DynamoDB table with on-demand billing."
4342
echo " -n table_name -- The name of the table to create."
4443
echo " -a attribute_definitions -- JSON file path of a list of attributes and their types."
4544
echo " -k key_schema -- JSON file path of a list of attributes and their key types."
46-
echo " -p provisioned_throughput -- Provisioned throughput settings for the table."
4745
echo ""
4846
}
4947

5048
# Retrieve the calling parameters.
51-
while getopts "n:a:k:p:h" option; do
49+
while getopts "n:a:k:h" option; do
5250
case "${option}" in
5351
n) table_name="${OPTARG}" ;;
5452
a) attribute_definitions="${OPTARG}" ;;
5553
k) key_schema="${OPTARG}" ;;
56-
p) provisioned_throughput="${OPTARG}" ;;
5754
h)
5855
usage
5956
return 0
@@ -85,24 +82,17 @@ function dynamodb_create_table() {
8582
return 1
8683
fi
8784

88-
if [[ -z "$provisioned_throughput" ]]; then
89-
errecho "ERROR: You must provide a provisioned throughput json file path the -p parameter."
90-
usage
91-
return 1
92-
fi
93-
9485
iecho "Parameters:\n"
9586
iecho " table_name: $table_name"
9687
iecho " attribute_definitions: $attribute_definitions"
9788
iecho " key_schema: $key_schema"
98-
iecho " provisioned_throughput: $provisioned_throughput"
9989
iecho ""
10090

10191
response=$(aws dynamodb create-table \
10292
--table-name "$table_name" \
10393
--attribute-definitions file://"$attribute_definitions" \
104-
--key-schema file://"$key_schema" \
105-
--provisioned-throughput "$provisioned_throughput")
94+
--billing-mode PAY_PER_REQUEST \
95+
--key-schema file://"$key_schema" )
10696

10797
local error_code=${?}
10898

aws-cli/bash-linux/dynamodb/scenario_getting_started_movies.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
# SPDX-License-Identifier: Apache-2.0
4-
# bashsupport disable=BP2002
4+
# bashsupport disable=BP2002
55

66
###############################################################################
77
#
@@ -65,8 +65,6 @@ function dynamodb_getting_started_movies() {
6565
get_input
6666
table_name=$get_input_result
6767

68-
local provisioned_throughput="ReadCapacityUnits=5,WriteCapacityUnits=5"
69-
7068
echo '[
7169
{"AttributeName": "year", "KeyType": "HASH"},
7270
{"AttributeName": "title", "KeyType": "RANGE"}
@@ -78,7 +76,7 @@ function dynamodb_getting_started_movies() {
7876
]' >"$attribute_definitions_json_file"
7977

8078
if dynamodb_create_table -n "$table_name" -a "$attribute_definitions_json_file" \
81-
-k "$key_schema_json_file" -p "$provisioned_throughput" 1>/dev/null; then
79+
-k "$key_schema_json_file" 1>/dev/null; then
8280
echo "Created a DynamoDB table named $table_name"
8381
else
8482
errecho "The table failed to create. This demo will exit."

aws-cli/bash-linux/dynamodb/tests/test_dynamodb_examples.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ function main() {
8585
iecho "***************SETUP STEPS******************"
8686
local test_table_name
8787
test_table_name=$(generate_random_name testcli)
88-
local test_provisioned_throughput="ReadCapacityUnits=5,WriteCapacityUnits=5"
8988
local test_key_schema_json_file="test_dynamodb_key_schema.json"
9089
local test_attr_definitions_json_file="test_dynamodb_attr_def.json"
9190
local test_key_json_file="test_dynamodb_key.json"
@@ -111,7 +110,7 @@ function main() {
111110
]' >"$test_attr_definitions_json_file"
112111

113112
run_test "Creating table" \
114-
"dynamodb_create_table -n $test_table_name -a $test_attr_definitions_json_file -k $test_key_schema_json_file -p $test_provisioned_throughput " \
113+
"dynamodb_create_table -n $test_table_name -a $test_attr_definitions_json_file -k $test_key_schema_json_file " \
115114
0
116115

117116
export exit_on_failure=false

0 commit comments

Comments
 (0)