Home > Software design >  DynamoDB.create_table erroring with `ArgumentError: no such member :billing_mode`
DynamoDB.create_table erroring with `ArgumentError: no such member :billing_mode`

Time:05-18

I am trying to create a new table through the aws-sdk(2.11.31) using the DynamoDB client like so;

        new_table_definition = {
          attribute_definitions: [
            {
              attribute_name: 'user',
              attribute_type: 'S'
            },
            {
              attribute_name: 'timestamp',
              attribute_type: 'N'
            },
            {
              attribute_name: 'uuid',
              attribute_type: 'S'
            }
          ],
          key_schema: [
            {
              attribute_name: 'uuid',
              key_type: 'HASH'
            },
            {
              attribute_name: 'timestamp',
              key_type: 'RANGE'
            }
          ],
          global_secondary_indexes: [
            {
              index_name: 'user-timestamp-index',
              key_schema: [
                {
                  attribute_name: 'user',
                  key_type: 'HASH'
                },
                {
                  attribute_name: 'timestamp',
                  key_type: 'RANGE'
                }
              ],
              projection: {
                projection_type: 'KEYS_ONLY'
              },
              provisioned_throughput: {
                read_capacity_units: 0,
                write_capacity_units: 0,
              }
            }
          ],
          billing_mode: "PAY_PER_REQUEST",
          provisioned_throughput: {
            read_capacity_units: 0,
            write_capacity_units: 0
          },
          table_name: "A_NEW_TABLE"
        }
        Dynamo::Table.create(new_table_definition)

However I get the following error: ArgumentError: no such member :billing_mode

From what I understand that is the correct key and formatting for the billing mode as described in the documentation for v2 of the sdk. Removing the billing mode creates the table fine but I am then forced to go into AWS console to manually change it to On-Demand.

Ruby - 2.3.0

Rails - 3.2.22.5

aws-sdk - 2.11.31

Relevant backtrace:

2.3.3 :464 >         Dynamo::Table.create(new_table_definition)
ArgumentError: no such member :billing_mode
    from shared/bundle/ruby/2.3.0/gems/aws-sdk-core-2.11.31/lib/seahorse/model/shapes.rb:212:in `member'
    from shared/bundle/ruby/2.3.0/gems/aws-sdk-core-2.11.31/lib/aws-sdk-core/plugins/dynamodb_simple_attributes.rb:165:in `block in structure'
    from shared/bundle/ruby/2.3.0/gems/aws-sdk-core-2.11.31/lib/aws-sdk-core/plugins/dynamodb_simple_attributes.rb:164:in `each'
    from shared/bundle/ruby/2.3.0/gems/aws-sdk-core-2.11.31/lib/aws-sdk-core/plugins/dynamodb_simple_attributes.rb:164:in `with_object'
    from shared/bundle/ruby/2.3.0/gems/aws-sdk-core-2.11.31/lib/aws-sdk-core/plugins/dynamodb_simple_attributes.rb:164:in `structure'
    from shared/bundle/ruby/2.3.0/gems/aws-sdk-core-2.11.31/lib/aws-sdk-core/plugins/dynamodb_simple_attributes.rb:152:in `apply'
    from shared/bundle/ruby/2.3.0/gems/aws-sdk-core-2.11.31/lib/aws-sdk-core/plugins/dynamodb_simple_attributes.rb:121:in `translate_input'
    from shared/bundle/ruby/2.3.0/gems/aws-sdk-core-2.11.31/lib/aws-sdk-core/plugins/dynamodb_simple_attributes.rb:111:in `call'
    from shared/bundle/ruby/2.3.0/gems/aws-sdk-core-2.11.31/lib/aws-sdk-core/plugins/jsonvalue_converter.rb:20:in `call'
    from shared/bundle/ruby/2.3.0/gems/aws-sdk-core-2.11.31/lib/aws-sdk-core/plugins/idempotency_token.rb:18:in `call'
    from shared/bundle/ruby/2.3.0/gems/aws-sdk-core-2.11.31/lib/aws-sdk-core/plugins/param_converter.rb:20:in `call'
    from shared/bundle/ruby/2.3.0/gems/aws-sdk-core-2.11.31/lib/seahorse/client/plugins/response_target.rb:21:in `call'
    from shared/bundle/ruby/2.3.0/gems/aws-sdk-core-2.11.31/lib/seahorse/client/request.rb:70:in `send_request'
    from shared/bundle/ruby/2.3.0/gems/aws-sdk-core-2.11.31/lib/seahorse/client/base.rb:207:in `block (2 levels) in define_operation_methods'

CodePudding user response:

The issue I was having specifically is with the gem version. It appears not to support billing_mode.

Another issue I also found in testing a newer version is actually with sending both the billing_mode and the provisioned_throughput values through at once. It's an either/or situation.

If read/write capacity mode is PAY_PER_REQUEST the value is set to 0. This line in this documentation caused the confusion https://docs.aws.amazon.com/sdk-for-ruby/v2/api/Aws/DynamoDB/Types/ProvisionedThroughput.html

See here it tells you NOT to pass it through: https://docs.aws.amazon.com/sdk-for-ruby/v2/api/Aws/DynamoDB/Client.html#create_table-instance_method

  • Related