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# ##############################################################################
3332function 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
0 commit comments