class Shred::Commands::DynamoDb

Public Instance Methods

create_table(name, region, read_capacity_units, write_capacity_units, hash_key: nil) click to toggle source
# File lib/shred/commands/dynamo_db.rb, line 50
def create_table(name, region, read_capacity_units, write_capacity_units, hash_key: nil)
  ddb = AWS::DynamoDB.new(region: region)
  if ddb.tables[name].exists?
    console.say_ok("Dynamo DB table #{name} already exists in region #{region}")
  else
    table = ddb.tables.create(name, read_capacity_units, write_capacity_units, hash_key)
    sleep 1 while table.status == :creating
    if table.status == :active
      console.say_ok("Created Dynamo DB table #{name} in region #{region}")
    else
      console.say_err("Failed to create Dynamo DB table #{name} in region #{region}: status #{table.status}")
    end
  end
end
mktable(name, region, read_capacity_units, write_capacity_units) click to toggle source
# File lib/shred/commands/dynamo_db.rb, line 16
def mktable(name, region, read_capacity_units, write_capacity_units)
  ::Dotenv.load

  create_table(name, region, read_capacity_units.to_i, write_capacity_units.to_i,
               hash_key: {options[:pk] => options[:pk_type]})
end
mktables() click to toggle source
# File lib/shred/commands/dynamo_db.rb, line 31
def mktables
  ::Dotenv.load

  prefix = cfg('table_prefix', required: false)

  cfg('tables').each do |(name, table_cfg)|
    name = "#{prefix}#{name}" if prefix
    name = interpolate_value(name)
    region = interpolate_value(table_cfg['region'])
    read_capacity_units = table_cfg['read_capacity_units'].to_i
    write_capacity_units = table_cfg['write_capacity_units'].to_i
    pk = table_cfg['primary_key'].fetch('name', 'id')
    pk_type = table_cfg['primary_key'].fetch('type', 'string')

    create_table(name, region, read_capacity_units, write_capacity_units, hash_key: {pk => pk_type})
  end
end