class Awscli::DynamoDB::Table
Public Class Methods
new(connection)
click to toggle source
# File lib/awscli/dynamo.rb, line 4 def initialize(connection) @conn = connection end
Public Instance Methods
create(options)
click to toggle source
# File lib/awscli/dynamo.rb, line 22 def create(options) key_schema, provisioned_throughput = {}, {} abort 'Invalid key type' unless %w(N NS S SS).include?(options[:pk_type]) key_schema['HashKeyElement'] = { 'AttributeName' => options[:pk_name], 'AttributeType' => options[:pk_type] } if options[:rk_name] abort '--rk_type is required if --rk-name is passed' unless options[:rk_name] abort 'Invalid key type' unless %w(N NS S SS).include?(options[:rk_type]) key_schema['RangeKeyElement'] = { 'AttributeName' => options[:rk_name], 'AttributeType' => options[:rk_type] } end provisioned_throughput['ReadCapacityUnits'] = options[:read_capacity] provisioned_throughput['WriteCapacityUnits'] = options[:write_capacity] @conn.create_table(options[:name], key_schema, provisioned_throughput) rescue Excon::Errors::BadRequest puts "[Error] Failed to create table. #{parse_excon_error_response($!)}" else puts "Create table #{options[:name]} successfully." end
delete(table_name)
click to toggle source
# File lib/awscli/dynamo.rb, line 52 def delete(table_name) @conn.delete_table(table_name) rescue Excon::Errors::BadRequest puts "[Error] Failed to delete table. #{parse_excon_error_response($!)}" else puts "Delete table #{table_name} successfully." end
describe(table_name)
click to toggle source
# File lib/awscli/dynamo.rb, line 46 def describe(table_name) puts @conn.describe_table(table_name).body.to_yaml rescue Excon::Errors::BadRequest puts 'Table not found' end
list(options)
click to toggle source
# File lib/awscli/dynamo.rb, line 8 def list(options) opts = {} table_data = [] opts['Limit'] = options[:limit] if options[:limit] @conn.list_tables(opts).body['TableNames'].each do |table| table_data << { :table => table } end if table_data.empty? puts 'No tables found' else Formatador.display_table(table_data) end end
update(options)
click to toggle source
# File lib/awscli/dynamo.rb, line 60 def update(options) provisioned_throughput = {} provisioned_throughput['ReadCapacityUnits'] = options[:read_capacity] provisioned_throughput['WriteCapacityUnits'] = options[:write_capacity] @conn.update_table(options[:name], provisioned_throughput) rescue Excon::Errors::BadRequest puts "[Error] Failed to update table. #{parse_excon_error_response($!)}" else puts "Table #{options[:name]} provisioned capacity updated successfully." end
Private Instance Methods
parse_excon_error_response(response)
click to toggle source
# File lib/awscli/dynamo.rb, line 73 def parse_excon_error_response(response) response.data[:body].match(/message.*/)[0].gsub(/[^A-Za-z0-9: ]/, '') end