diff --git a/README.md b/README.md index 0dc35cf5..2b92d2d2 100644 --- a/README.md +++ b/README.md @@ -1126,6 +1126,10 @@ Listed below are all configuration options. * `http_read_timeout`:The number of seconds to wait for HTTP response data. Default option value is `nil`. If not specified effected value is `60` +* `http_proxy`: A proxy to send requests through. Default option value is `nil`. +* `create_table_enabled`: if `true`, Dynamoid creates table if table not exist; + if `false`, Dynamoid logs error message for not able to create table in DynamoDB. + Default is `false` ## Concurrency diff --git a/lib/dynamoid/adapter_plugin/aws_sdk_v3.rb b/lib/dynamoid/adapter_plugin/aws_sdk_v3.rb index 6695a36f..0633abc5 100644 --- a/lib/dynamoid/adapter_plugin/aws_sdk_v3.rb +++ b/lib/dynamoid/adapter_plugin/aws_sdk_v3.rb @@ -67,7 +67,7 @@ class AwsSdkV3 } BATCH_WRITE_ITEM_REQUESTS_LIMIT = 25 - CONNECTION_CONFIG_OPTIONS = %i[endpoint region http_continue_timeout http_idle_timeout http_open_timeout http_read_timeout].freeze + CONNECTION_CONFIG_OPTIONS = %i[endpoint region http_continue_timeout http_idle_timeout http_open_timeout http_read_timeout http_proxy].freeze attr_reader :table_cache @@ -282,6 +282,11 @@ def batch_delete_item(options) # @option options [Boolean] sync Wait for table status to be ACTIVE? # @since 1.0.0 def create_table(table_name, key = :id, options = {}) + unless Dynamoid.config.create_table_enabled + Dynamoid.logger.error "Table #{table_name} is not created as create_table_enabled is disabled" + return false + end + Dynamoid.logger.info "Creating #{table_name} table. This could take a while." CreateTable.new(client, table_name, key, options).call true diff --git a/lib/dynamoid/config.rb b/lib/dynamoid/config.rb index 07880bfd..756c1b12 100644 --- a/lib/dynamoid/config.rb +++ b/lib/dynamoid/config.rb @@ -59,6 +59,8 @@ module Config option :http_idle_timeout, default: nil # - default: 5 option :http_open_timeout, default: nil # - default: 15 option :http_read_timeout, default: nil # - default: 60 + option :http_proxy, default: nil + option :create_table_enabled, default: true # The default logger for Dynamoid: either the Rails logger or just stdout. # diff --git a/spec/dynamoid/adapter_plugin/aws_sdk_v3_spec.rb b/spec/dynamoid/adapter_plugin/aws_sdk_v3_spec.rb index 2386cb5d..d68fe080 100644 --- a/spec/dynamoid/adapter_plugin/aws_sdk_v3_spec.rb +++ b/spec/dynamoid/adapter_plugin/aws_sdk_v3_spec.rb @@ -1242,11 +1242,15 @@ def dynamo_request(table_name, scan_hash = {}, select_opts = {}) before do Dynamoid.configure.http_open_timeout = 30 + Dynamoid.configure.http_proxy = 'http://proxy' end + after { Dynamoid.configure.http_proxy = nil } + it 'not nil options entried' do - expect(subject.keys).to contain_exactly(:endpoint, :log_formatter, :log_level, :logger, :http_open_timeout) + expect(subject.keys).to contain_exactly(:endpoint, :log_formatter, :log_level, :logger, :http_open_timeout, :http_proxy) expect(subject[:http_open_timeout]).to eq 30 + expect(subject[:http_proxy]).to eq 'http://proxy' end end end