class AwsCli::CLI::DYNAMO::Item

Public Instance Methods

batch_get() click to toggle source
# File lib/awscli/cli/dynamo/item.rb, line 212
def batch_get
  unless options[:requests]
    abort 'option --requests is required'
  end
  options[:requests].each do |request|
    unless request =~ /^(.*?)(?:,((N|S|B|NS|SS|BS)=(.*?))(:(N|S|B|NS|SS|BS)=(.*?))*)+$/
      abort 'Invalid --request format, see `awscli dynamo item help batch_get` for usage examples'
    end
  end
  create_dynamo_object
  @ddb.batch_get options
end
batch_write() click to toggle source
# File lib/awscli/cli/dynamo/item.rb, line 240
def batch_write
  unless options[:put_requests] or options[:delete_requests]
    abort 'option --put-requests or --delete-requests is required to perform batch_write'
  end
  options[:put_requests] and options[:put_requests].each do |put_request|
    unless put_request =~ /^(.*?)(?:,((.*?):(N|S|B|NS|SS|BS):(.*?))*)+$/
      abort 'Invalid --put-requests format, see `awscli dynamo item help batch_write` for usage examples'
    end
  end
  options[:delete_requests] and options[:delete_requests].each do |delete_request|
    unless delete_request =~ /^(.*?)(?:,((N|S|B|NS|SS|BS)=(.*?))(:(N|S|B|NS|SS|BS)=(.*?))*)+$/
      abort 'Invalid --delete-requests format, see `awscli dynamo item help batch_write` for usage examples'
    end
  end
  create_dynamo_object
  @ddb.batch_write options
end
delete() click to toggle source
# File lib/awscli/cli/dynamo/item.rb, line 116
def delete
  unless options[:table_name] and options[:hash_key]
    abort 'required options --table-name, --hash-key'
  end
  if options[:expected_exists]
    abort '--expected-exists only accepts true or false' unless %w(true false).include?(options[:expected_exists])
  end
  create_dynamo_object
  @ddb.delete options
end
get() click to toggle source
# File lib/awscli/cli/dynamo/item.rb, line 71
def get
  unless options[:table_name] and options[:hash_key]
    abort 'required options --table-name, --hash-key'
  end
  create_dynamo_object
  @ddb.get options
end
put() click to toggle source
# File lib/awscli/cli/dynamo/item.rb, line 54
def put
  unless options[:table_name] and options[:item]
    abort 'required options --table-name, --item'
  end
  if options[:expected_exists]
    abort '--expected-exists only accepts true or false' unless %w(true false).include?(options[:expected_exists])
  end
  create_dynamo_object
  @ddb.put options
end
query() click to toggle source
# File lib/awscli/cli/dynamo/item.rb, line 144
def query
  unless options[:table_name] and options[:hash_key_value]
    abort 'options --table-name and --hash-key-value are required'
  end
  abort 'invalid --hash-key-value format' unless options[:hash_key_value] =~ /^(.*?),(.*?)$/
  if options[:scan_index_forward]
    abort 'invalid option --scan-index-forward value' unless options[:scan_index_forward] =~ /true|false/
  end
  if options[:range_key_filter]
    abort 'invalid --range-key-filter format' unless options[:range_key_filter] =~ /^(BETWEEN|BEGINS_WITH|EQ|LE|LT|GE|GT),(N|S|B|NS|SS|BS),(.*?)$/
  end
  if options[:start_key]
    abort 'Invalid --start-key format' unless options[:start_key] =~ /^(.*?),(.*?)$/
  end
  if options[:start_range_key]
    abort 'Invalid --start-range-key format' unless options[:start_range_key] =~ /^(.*?),(.*?)$/
  end
  create_dynamo_object
  @ddb.query options
end
scan() click to toggle source
# File lib/awscli/cli/dynamo/item.rb, line 177
def scan
  unless options[:table_name]
    abort 'option --table-name is required.'
  end
  if options[:scan_filter]
    abort 'Invalid --scan-filter format' unless options[:scan_filter] =~ /^(BETWEEN|BEGINS_WITH|EQ|LE|LT|GE|GT),(.*?),(N|S|B|NS|SS|BS),(.*?)$/
  end
  if options[:start_key]
    abort 'Invalid --start-key format' unless options[:start_key] =~ /^(.*?),(.*?)$/
  end
  if options[:start_range_key]
    abort 'Invalid --start-range-key format' unless options[:start_range_key] =~ /^(.*?),(.*?)$/
  end
  create_dynamo_object
  @ddb.scan options
end
update() click to toggle source
# File lib/awscli/cli/dynamo/item.rb, line 92
def update
  unless options[:table_name] and options[:hash_key] and options[:attr_updates]
    abort 'required options --table-name, --hash-kye, --attr-updates'
  end
  if options[:expected_exists]
    abort '--expected-exists only accepts true or false' unless %w(true false).include?(options[:expected_exists])
  end
  create_dynamo_object
  @ddb.update options
end

Private Instance Methods

create_dynamo_object() click to toggle source
# File lib/awscli/cli/dynamo/item.rb, line 260
def create_dynamo_object
  puts 'Dynamo Establishing Connection...'
  $dynamo_conn =  if parent_options[:region]
                    Awscli::Connection.new.request_dynamo(parent_options[:region])
                  else
                    Awscli::Connection.new.request_dynamo
                  end
  puts 'Dynamo Establishing Connection... OK'
  @ddb = Awscli::DynamoDB::Items.new($dynamo_conn)
end