Class: Awscli::DynamoDB::Table
- Inherits:
-
Object
- Object
- Awscli::DynamoDB::Table
- Defined in:
- lib/awscli/dynamo.rb
Instance Method Summary collapse
- #create(options) ⇒ Object
- #delete(table_name) ⇒ Object
- #describe(table_name) ⇒ Object
-
#initialize(connection) ⇒ Table
constructor
A new instance of Table.
- #list(options) ⇒ Object
- #update(options) ⇒ Object
Constructor Details
#initialize(connection) ⇒ Table
Returns a new instance of Table.
4 5 6 |
# File 'lib/awscli/dynamo.rb', line 4 def initialize(connection) @conn = connection end |
Instance Method Details
#create(options) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/awscli/dynamo.rb', line 22 def create() key_schema, provisioned_throughput = {}, {} abort 'Invalid key type' unless %w(N NS S SS).include?([:pk_type]) key_schema['HashKeyElement'] = { 'AttributeName' => [:pk_name], 'AttributeType' => [:pk_type] } if [:rk_name] abort '--rk_type is required if --rk-name is passed' unless [:rk_name] abort 'Invalid key type' unless %w(N NS S SS).include?([:rk_type]) key_schema['RangeKeyElement'] = { 'AttributeName' => [:rk_name], 'AttributeType' => [:rk_type] } end provisioned_throughput['ReadCapacityUnits'] = [:read_capacity] provisioned_throughput['WriteCapacityUnits'] = [:write_capacity] @conn.create_table([:name], key_schema, provisioned_throughput) rescue Excon::Errors::BadRequest puts "[Error] Failed to create table. #{parse_excon_error_response($!)}" else puts "Create table #{[:name]} successfully." end |
#delete(table_name) ⇒ Object
52 53 54 55 56 57 58 |
# 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) ⇒ Object
46 47 48 49 50 |
# 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) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/awscli/dynamo.rb', line 8 def list() opts = {} table_data = [] opts['Limit'] = [:limit] if [: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) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/awscli/dynamo.rb', line 60 def update() provisioned_throughput = {} provisioned_throughput['ReadCapacityUnits'] = [:read_capacity] provisioned_throughput['WriteCapacityUnits'] = [:write_capacity] @conn.update_table([:name], provisioned_throughput) rescue Excon::Errors::BadRequest puts "[Error] Failed to update table. #{parse_excon_error_response($!)}" else puts "Table #{[:name]} provisioned capacity updated successfully." end |