Skip to content
This repository has been archived by the owner on Feb 3, 2025. It is now read-only.

GameAnalytics/current

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DynamoDB client for Erlang

Build Status

Current is an Erlang client for Amazons DynamoDB service. It exposes the raw JSON API described in the DynamoDB documentation, taking input and giving output in terms compatible with jiffy. Current can also retry requests when appropriate, for example when you're throttled due using all your provisioned throughput or using all available socket connections to DynamoDB.

Dependencies

Usage

Fetch and compile all application dependencies:

$ rebar get compile

Example usage:

1> application:ensure_all_started(current).
{ok,[current]}
3> application:set_env(current, region, <<"us-east-1">>).
ok
4> application:set_env(current, access_key, <<"foo">>).
ok
5> application:set_env(current, secret_access_key, <<"bar">>).
ok

6> GetRequest = {[{<<"TableName">>, <<"current_test_table">>}, {<<"Key">>, {[{<<"hash_key">>, {[{<<"N">>, <<"1">>}]}}, {<<"range_key">>, {[{<<"N">>, <<"1">>}]}}]}}]}.
{[{<<"TableName">>,<<"current_test_table">>},
  {<<"Key">>,
   {[{<<"hash_key">>,{[{<<"N">>,<<"1">>}]}},
     {<<"range_key">>,{[{<<"N">>,<<"1">>}]}}]}}]}

7> current:get_item(GetRequest).
{ok,{[{<<"ConsumedCapacity">>,
       {[{<<"CapacityUnits">>,0.5},
         {<<"TableName">>,<<"current_test_table">>}]}},
      {<<"Item">>,
       {[{<<"hash_key">>,{[{<<"N">>,<<"1">>}]}},
         {<<"range_key">>,{[{<<"N">>,<<"1">>}]}}]}}]}}

With the new maps datastructure life will be great.

Instrumentation

Current will call functions in the module specified in the callback_mod environment variable. At the moment, you need to implement two functions: request_complete/3 and request_error/3, see src/current_callback.erl.

request_complete(Operation, StartTimestamp, ConsumedCapacity) ->
    statman_histogram:record_value({ddb, Operation}, StartTimestamp),
    ok.

All calls to DynamoDB will have the ReturnConsumedCapacity value set to TOTAL by default. When DynamoDB returns the ConsumedCapacity, current will forward it to your callback module. Keep in mind that for batch requests it is a list containing capacity for one or more tables.

Testing

If you provide AWS credentials in priv/aws_credentials.term (see priv/aws_credentials_term.template), you can run the test suite. Tables will be created under your account.

To run all tests use rebar eunit