Skip to content

Commit

Permalink
Merge pull request esl#39 from talko/lsi
Browse files Browse the repository at this point in the history
Amazon DDB 20120810 API
  • Loading branch information
gleber committed May 7, 2013
2 parents 3b5c00a + 897001e commit 3ea158e
Show file tree
Hide file tree
Showing 12 changed files with 5,272 additions and 199 deletions.
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ REBAR=$(shell which rebar || echo ./rebar)
# eventually this should be just ebin/*.beam, but there are a number
# of warnings in other files. Just check the clean files for now.
CHECK_FILES=\
ebin/erlcloud_ddb1.beam \
ebin/erlcloud_ddb.beam \
ebin/erlcloud_ddb1.beam \
ebin/erlcloud_ddb2.beam \
ebin/erlcloud_ddb_impl.beam \
ebin/erlcloud_ddb_util.beam \
ebin/erlcloud_aws.beam

# Checks on the eunit files can help find bad specs and other issues,
Expand All @@ -15,7 +18,9 @@ CHECK_FILES=\
CHECK_EUNIT_FILES=\
$(CHECK_FILES) \
.eunit/erlcloud_ec2_tests.beam \
.eunit/erlcloud_ddb_tests.beam
.eunit/erlcloud_ddb_tests.beam \
.eunit/erlcloud_ddb2_tests.beam \
.eunit/erlcloud_ddb_util_tests.beam

all: get-deps compile

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Service APIs implemented:
- Amazon SimpleDB
- Amazon Mechanical Turk
- Amazon CloudWatch (MON)
- Amazon DynamoDB (DDB)
- Amazon DynamoDB (ddb2)

All API functions have been implemented. Not all functions
have been thoroughly tested, so exercise care when integrating
Expand Down
2 changes: 1 addition & 1 deletion include/erlcloud_aws.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
ddb_scheme="https://"::string(),
ddb_host="dynamodb.us-east-1.amazonaws.com"::string(),
ddb_port=80::non_neg_integer(),
ddb_retry=fun erlcloud_ddb1:retry/2::erlcloud_ddb1:retry_fun(),
ddb_retry=fun erlcloud_ddb_impl:retry/2::erlcloud_ddb_impl:retry_fun(),
access_key_id::string()|undefined|false,
secret_access_key::string()|undefined|false,
security_token=undefined::string()|undefined
Expand Down
116 changes: 116 additions & 0 deletions include/erlcloud_ddb2.hrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
-type date_time() :: number().
-type table_status() :: creating | updating | deleting | active.

-record(ddb2_local_secondary_index_description,
{index_name :: erlcloud_ddb2:index_name(),
index_size_bytes :: integer(),
item_count :: integer(),
key_schema :: erlcloud_ddb2:key_schema(),
projection :: erlcloud_ddb2:projection()
}).
-record(ddb2_provisioned_throughput_description,
{last_decrease_date_time :: date_time(),
last_increase_date_time :: date_time(),
number_of_decreases_today :: integer(),
read_capacity_units :: pos_integer(),
write_capacity_units :: pos_integer()
}).
-record(ddb2_table_description,
{attribute_definitions :: erlcloud_ddb2:attr_defs(),
creation_date_time :: number(),
item_count :: integer(),
key_schema :: erlcloud_ddb2:key_schema(),
local_secondary_indexes :: [#ddb2_local_secondary_index_description{}],
provisioned_throughput :: #ddb2_provisioned_throughput_description{},
table_name :: binary(),
table_size_bytes :: integer(),
table_status :: table_status()
}).
-record(ddb2_consumed_capacity,
{capacity_units :: number(),
table_name :: erlcloud_ddb2:table_name()
}).
-record(ddb2_item_collection_metrics,
{item_collection_key :: erlcloud_ddb2:out_attr_value(),
size_estimate_range_gb :: {number(), number()}
}).

-record(ddb2_batch_get_item_response,
{table :: erlcloud_ddb2:table_name(),
items :: [erlcloud_ddb2:out_item()]
}).
-record(ddb2_batch_get_item,
{consumed_capacity :: [#ddb2_consumed_capacity{}],
responses :: [#ddb2_batch_get_item_response{}],
unprocessed_keys :: [erlcloud_ddb2:batch_get_item_request_item()]
}).

-record(ddb2_batch_write_item_response,
{table :: erlcloud_ddb2:table_name(),
consumed_capacity_units :: number()
}).
-record(ddb2_batch_write_item,
{consumed_capacity :: [#ddb2_consumed_capacity{}],
item_collection_metrics :: [{erlcloud_ddb2:table_name(), [#ddb2_item_collection_metrics{}]}],
unprocessed_items :: [erlcloud_ddb2:batch_write_item_request_item()]
}).

-record(ddb2_create_table,
{table_description :: #ddb2_table_description{}
}).

-record(ddb2_delete_item,
{attributes :: erlcloud_ddb2:out_item(),
consumed_capacity :: #ddb2_consumed_capacity{},
item_collection_metrics :: #ddb2_item_collection_metrics{}
}).

-record(ddb2_delete_table,
{table_description :: #ddb2_table_description{}
}).

-record(ddb2_describe_table,
{table :: #ddb2_table_description{}
}).

-record(ddb2_get_item,
{item :: erlcloud_ddb2:out_item(),
consumed_capacity :: #ddb2_consumed_capacity{}
}).

-record(ddb2_list_tables,
{table_names :: [erlcloud_ddb2:table_name()],
last_evaluated_table_name :: erlcloud_ddb2:table_name()
}).

-record(ddb2_put_item,
{attributes :: erlcloud_ddb2:out_item(),
consumed_capacity :: #ddb2_consumed_capacity{},
item_collection_metrics :: #ddb2_item_collection_metrics{}
}).

-record(ddb2_q,
{consumed_capacity :: #ddb2_consumed_capacity{},
count :: non_neg_integer(),
items :: [erlcloud_ddb2:out_item()],
last_evaluated_key :: erlcloud_ddb2:key()
}).

-record(ddb2_scan,
{consumed_capacity :: #ddb2_consumed_capacity{},
count :: non_neg_integer(),
items :: [erlcloud_ddb2:out_item()],
last_evaluated_key :: erlcloud_ddb2:key(),
scanned_count :: non_neg_integer()
}).

-record(ddb2_update_item,
{attributes :: erlcloud_ddb2:out_item(),
consumed_capacity :: #ddb2_consumed_capacity{},
item_collection_metrics :: #ddb2_item_collection_metrics{}
}).

-record(ddb2_update_table,
{table_description :: #ddb2_table_description{}
}).

111 changes: 77 additions & 34 deletions src/erlcloud_ddb.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
%% @doc
%% An Erlang interface to Amazon's DynamoDB.
%%
%% [http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/operationlist.html]
%% [http://aws.amazon.com/archives/Amazon-DynamoDB/8498019230173117]
%%
%% Currently the entire 20111205 API is implemented.
%% erlcloUd_ddb implements the entire 20111205 API. erlcloud_ddb2
%% implements a newer version.
%%
%% Method names match DynamoDB operations converted to
%% lower_case_with_underscores. The one exception is query, which is
Expand Down Expand Up @@ -63,9 +64,11 @@
%% to handle conditional check failures, match `{error,
%% {<<"ConditionalCheckFailedException">>, _}}'.
%%
%% `erlcloud_ddb_util' provides a higher level API that implements common
%% operations that may require multiple DynamoDB API calls.
%%
%% `erlcloud_ddb1' provides a lower level API that takes JSON terms as
%% defined by `jsx'. It may be useful to pass options that are not yet
%% supported by this module.
%% defined by `jsx'.
%%
%% See the unit tests for additional usage examples beyond what are
%% provided for each function.
Expand Down Expand Up @@ -98,10 +101,76 @@
update_table/3, update_table/4, update_table/5
]).

-export_type([table_name/0, hash_range_key/0, in_attr/0, out_item/0, key_schema/0,
batch_get_item_request_item/0,
batch_write_item_request_item/0
]).
-export_type(
[attr_name/0,
attr_type/0,
batch_get_item_request_item/0,
batch_get_item_return/0,
batch_write_item_delete/0,
batch_write_item_put/0,
batch_write_item_request/0,
batch_write_item_request_item/0,
batch_write_item_return/0,
boolean_opt/1,
comparison_op/0,
create_table_return/0,
ddb_opts/0,
ddb_return/2,
delete_item_opt/0,
delete_item_opts/0,
delete_item_return/0,
delete_table_return/0,
describe_table_return/0,
get_item_opt/0,
get_item_opts/0,
hash_key/0,
hash_range_key/0,
in_attr/0,
in_attr_data/0,
in_attr_data_scalar/0,
in_attr_data_set/0,
in_attr_typed_value/0,
in_attr_value/0,
in_expected/0,
in_expected_item/0,
in_item/0,
in_update/0,
in_updates/0,
item_return/0,
key/0,
key_schema/0,
key_schema_value/0,
list_tables_opt/0,
list_tables_opts/0,
list_tables_return/0,
maybe_list/1,
ok_return/1,
out_attr/0,
out_attr_value/0,
out_item/0,
out_opt/0,
out_type/0,
put_item_opt/0,
put_item_opts/0,
put_item_return/0,
q_opt/0,
q_opts/0,
q_return/0,
range_key/0,
range_key_condition/0,
return_value/0,
scan_filter/0,
scan_filter_item/0,
scan_opt/0,
scan_opts/0,
scan_return/0,
table_name/0,
update_action/0,
update_item_opt/0,
update_item_opts/0,
update_item_return/0,
update_table_return/0
]).

%%%------------------------------------------------------------------------------
%%% Library initialization.
Expand Down Expand Up @@ -603,8 +672,6 @@ batch_get_item(RequestItems, Opts) ->

%%------------------------------------------------------------------------------
%% @doc
%% DynamoDB API:
%% [http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/API_BatchGetItems.html]
%%
%% ===Example===
%%
Expand Down Expand Up @@ -718,8 +785,6 @@ batch_write_item(RequestItems, Opts) ->

%%------------------------------------------------------------------------------
%% @doc
%% DynamoDB API:
%% [http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/API_BatchWriteItem.html]
%%
%% ===Example===
%%
Expand Down Expand Up @@ -774,8 +839,6 @@ create_table(Table, KeySchema, ReadUnits, WriteUnits, Opts) ->

%%------------------------------------------------------------------------------
%% @doc
%% DynamoDB API:
%% [http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/API_CreateTable.html]
%%
%% ===Example===
%%
Expand Down Expand Up @@ -829,8 +892,6 @@ delete_item(Table, Key, Opts) ->

%%------------------------------------------------------------------------------
%% @doc
%% DynamoDB API:
%% [http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/API_DeleteItem.html]
%%
%% ===Example===
%%
Expand Down Expand Up @@ -875,8 +936,6 @@ delete_table(Table, Opts) ->

%%------------------------------------------------------------------------------
%% @doc
%% DynamoDB API:
%% [http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/API_DeleteTable.html]
%%
%% ===Example===
%%
Expand Down Expand Up @@ -929,8 +988,6 @@ describe_table(Table, Opts) ->

%%------------------------------------------------------------------------------
%% @doc
%% DynamoDB API:
%% [http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/API_DescribeTables.html]
%%
%% ===Example===
%%
Expand Down Expand Up @@ -969,8 +1026,6 @@ get_item(Table, Key, Opts) ->

%%------------------------------------------------------------------------------
%% @doc
%% DynamoDB API:
%% [http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/API_GetItem.html]
%%
%% ===Example===
%%
Expand Down Expand Up @@ -1025,8 +1080,6 @@ list_tables(Opts) ->

%%------------------------------------------------------------------------------
%% @doc
%% DynamoDB API:
%% [http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/API_ListTables.html]
%%
%% ===Example===
%%
Expand Down Expand Up @@ -1077,8 +1130,6 @@ put_item(Table, Item, Opts) ->

%%------------------------------------------------------------------------------
%% @doc
%% DynamoDB API:
%% [http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/API_PutItem.html]
%%
%% ===Example===
%%
Expand Down Expand Up @@ -1160,8 +1211,6 @@ q(Table, HashKey, Opts) ->

%%------------------------------------------------------------------------------
%% @doc
%% DynamoDB API:
%% [http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/API_Query.html]
%%
%% ===Example===
%%
Expand Down Expand Up @@ -1245,8 +1294,6 @@ scan(Table, Opts) ->

%%------------------------------------------------------------------------------
%% @doc
%% DynamoDB API:
%% [http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/API_Scan.html]
%%
%% ===Example===
%%
Expand Down Expand Up @@ -1323,8 +1370,6 @@ update_item(Table, Key, Updates, Opts) ->

%%------------------------------------------------------------------------------
%% @doc
%% DynamoDB API:
%% [http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/API_UpdateItem.html]
%%
%% ===Example===
%%
Expand Down Expand Up @@ -1371,8 +1416,6 @@ update_table(Table, ReadUnits, WriteUnits, Opts) ->

%%------------------------------------------------------------------------------
%% @doc
%% DynamoDB API:
%% [http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/API_UpdateTable.html]
%%
%% ===Example===
%%
Expand Down
Loading

0 comments on commit 3ea158e

Please sign in to comment.