Last active
August 29, 2015 14:16
-
-
Save Sjeanpierre/1fc5bf956682ac8b353d to your computer and use it in GitHub Desktop.
Create dynamodb table with global index example aws-sdk ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def setup_dynamo | |
options = { | |
:table_name => 'servers', | |
:attribute_definitions => [ | |
{ | |
:attribute_name => 'uid', | |
:attribute_type => 'S' | |
}, | |
{ | |
:attribute_name => 'private_ip', | |
:attribute_type => 'S' | |
}, | |
{ | |
:attribute_name => 'public_ip', | |
:attribute_type => 'S' | |
} | |
], | |
:key_schema => [ | |
{ | |
:attribute_name => 'uid', | |
:key_type => 'HASH' | |
} | |
], | |
global_secondary_indexes: [ | |
{ | |
index_name: 'private_ip', | |
key_schema: [ | |
{ | |
attribute_name: 'private_ip', | |
key_type: 'HASH', | |
}, | |
], | |
projection: { | |
projection_type: 'ALL', | |
}, | |
:provisioned_throughput => { | |
read_capacity_units: 1, | |
write_capacity_units: 1, | |
}}, | |
{ | |
index_name: 'public_ip', | |
key_schema: [ | |
{ | |
attribute_name: 'public_ip', | |
key_type: 'HASH', | |
}, | |
], | |
projection: { | |
projection_type: 'ALL', | |
}, | |
:provisioned_throughput => { | |
read_capacity_units: 1, | |
write_capacity_units: 1, | |
}} | |
], | |
:provisioned_throughput => { | |
read_capacity_units: 1, | |
write_capacity_units: 1, | |
}, | |
} | |
table_list = $dynamodb.list_tables | |
$dynamodb.create_table(options) unless table_list.table_names.include?(options[:table_name]) | |
rescue => error | |
puts 'Encountered an error setting up Dynamo' | |
puts "#{error.message}" | |
exit(1) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment