Module erlcloud_ddb_streams

An Erlang interface to Amazon's DynamoDB Streams.

Authors: Smiler Lee (smilerlee@live.com), Nicholas Lundgaard (nalundgaard@gmail.com).

Description

An Erlang interface to Amazon's DynamoDB Streams.

http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Streams.html

Method names match DynamoDB Streams operations converted to lower_case_with_underscores.

Required parameters are passed as function arguments. In addition all methods take an options proplist argument which can be used to pass optional parameters.

Output is in the form of {ok, Value} or {error, Reason}. The format of Value is controlled by the out option, which defaults to simple. The possible values are:

* simple - The most interesting part of the output. For example list_streams will return the streams, describe_stream will return the stream description.

* record - A record containing all the information from the DynamoDB Streams response except field types. This is useful if you need more detailed information than what is returned with simple. For example, with list_streams the record will contain the last evaluated stream ARN which can be used to continue the operation.

* typed_record - A record containing all the information from the DynamoDB Streams response. All field values are returned with type information. This option only makes sense to get_records.

* json - The output from DynamoDB Streams as processed by jsx:decode but with no further manipulation. This would rarely be useful, unless the DynamoDB Streams API is updated to include data that is not yet parsed correctly.

DynamoDB Streams errors are return in the form {error, {ErrorCode, Message}} where ErrorCode and 'Message' are both binary strings. So to handle limit exceeded exception, match {error, {<<"LimitExceededException">>, _}}.

As to the error retries, we use erlcloud_retry:default_retry/1 as the default retry strategy, this behaviour can be changed through aws_config().

Data Types

attr()

attr() = untyped_attr() | typed_attr()

attr_name()

attr_name() = binary()

aws_region()

aws_region() = binary()

ddb_streams_return()

ddb_streams_return(Record, Simple) = {ok, json_term() | Record | Simple} | {error, term()}

describe_stream_opt()

describe_stream_opt() = {exclusive_start_shard_id, shard_id()} | {limit, 1..100} | out_opt()

describe_stream_opts()

describe_stream_opts() = [describe_stream_opt()]

describe_stream_return()

describe_stream_return() = ddb_streams_return(#ddb_streams_describe_stream{}, #ddb_streams_stream_description{})

event_id()

event_id() = binary()

event_name()

event_name() = insert | modify | remove

event_source()

event_source() = binary()

event_version()

event_version() = binary()

get_records_opt()

get_records_opt() = {limit, 1..1000} | out_opt()

get_records_opts()

get_records_opts() = [get_records_opt()]

get_records_return()

get_records_return() = ddb_streams_return(#ddb_streams_get_records{}, [#ddb_streams_record{}])

get_shard_iterator_opt()

get_shard_iterator_opt() = {sequence_number, sequence_number()} | out_opt()

get_shard_iterator_opts()

get_shard_iterator_opts() = [get_shard_iterator_opt()]

get_shard_iterator_return()

get_shard_iterator_return() = ddb_streams_return(#ddb_streams_get_shard_iterator{}, shard_iterator())

hash_key_name()

hash_key_name() = attr_name()

item()

item() = [attr()]

json_term()

json_term() = jsx:json_term()

key()

key() = [attr(), ...]

key_schema()

key_schema() = hash_key_name() | {hash_key_name(), range_key_name()}

list_streams_opt()

list_streams_opt() = {exclusive_start_stream_arn, stream_arn()} | {limit, 1..100} | {table_name, table_name()} | out_opt()

list_streams_opts()

list_streams_opts() = [list_streams_opt()]

list_streams_return()

list_streams_return() = ddb_streams_return(#ddb_streams_list_streams{}, [#ddb_streams_stream{}])

out_opt()

out_opt() = {out, out_type()}

out_type()

out_type() = json | record | typed_record | simple

range_key_name()

range_key_name() = attr_name()

sequence_number()

sequence_number() = binary()

sequence_number_range()

sequence_number_range() = {sequence_number(), sequence_number()} | {sequence_number(), undefined}

shard_id()

shard_id() = binary()

shard_iterator()

shard_iterator() = binary()

shard_iterator_type()

shard_iterator_type() = trim_horizon | latest | at_sequence_number | after_sequence_number

stream_arn()

stream_arn() = binary()

stream_label()

stream_label() = binary()

stream_status()

stream_status() = enabling | enabled | disabling | disabled

stream_view_type()

stream_view_type() = keys_only | new_image | old_image | new_and_old_images

table_name()

table_name() = binary()

typed_attr()

typed_attr() = {attr_name(), typed_attr_value()}

typed_attr_value()

typed_attr_value() = {s, binary()} | {n, number()} | {b, binary()} | {bool, boolean()} | {null, true} | {ss, [binary(), ...]} | {ns, [number(), ...]} | {bs, [binary(), ...]} | {l, [typed_attr_value()]} | {m, [typed_attr()]}

untyped_attr()

untyped_attr() = {attr_name(), untyped_attr_value()}

untyped_attr_value()

untyped_attr_value() = binary() | number() | boolean() | undefined | [binary()] | [number()] | [untyped_attr_value()] | [untyped_attr()]

Function Index

configure/2
configure/3
describe_stream/1
describe_stream/2
describe_stream/3 DynamoDB Streams API: http://docs.aws.amazon.com/dynamodbstreams/latest/APIReference/API_DescribeStream.html
get_records/1
get_records/2
get_records/3 DynamoDB Streams API: http://docs.aws.amazon.com/dynamodbstreams/latest/APIReference/API_GetRecords.html
get_shard_iterator/3
get_shard_iterator/4
get_shard_iterator/5 DynamoDB API: http://docs.aws.amazon.com/dynamodbstreams/latest/APIReference/API_GetShardIterator.html
list_streams/0
list_streams/1
list_streams/2 DynamoDB API: http://docs.aws.amazon.com/dynamodbstreams/latest/APIReference/API_ListStreams.html
new/2
new/3

Function Details

configure/2

configure(AccessKeyID::string(), SecretAccessKey::string()) -> ok

configure/3

configure(AccessKeyID::string(), SecretAccessKey::string(), Host::string()) -> ok

describe_stream/1

describe_stream(StreamArn::stream_arn()) -> describe_stream_return()

describe_stream/2

describe_stream(StreamArn::stream_arn(), Opts::describe_stream_opts()) -> describe_stream_return()

describe_stream/3

describe_stream(StreamArn::stream_arn(), Opts::describe_stream_opts(), Config::aws_config()) -> describe_stream_return()

DynamoDB Streams API: http://docs.aws.amazon.com/dynamodbstreams/latest/APIReference/API_DescribeStream.html

Example

Describe a stream.

erlcloud_ddb_streams:describe_stream(<<"arn:aws:dynamodb:us-west-2:111122223333:table/Forum/stream/2015-05-20T20:51:10.252">>). {ok, #ddb_streams_stream_description{ creation_request_date_time = 1437677671.062, key_schema = {<<"ForumName">>, <<"Subject">>}, last_evaluated_shard_id = undefined, shards = [#ddb_streams_shard{ parent_shard_id = <<"shardId-00000001414562045508-2bac9cd1">>, sequence_number_range = {<<"20500000000000000910398">>, <<"20500000000000000910398">>}, shard_id = <<"shardId-00000001414562045508-2bac9cd2">>}], stream_arn = <<"arn:aws:dynamodb:us-west-2:111122223333:table/Forum/stream/2015-05-20T20:51:10.252">>, stream_label = <<"2015-05-20T20:51:10.252">>, stream_status = disabled, stream_view_type = new_and_old_images, table_name = <<"Forum">>}}

get_records/1

get_records(ShardIterator::shard_iterator()) -> get_records_return()

get_records/2

get_records(ShardIterator::shard_iterator(), Opts::get_records_opts()) -> get_records_return()

get_records/3

get_records(ShardIterator::shard_iterator(), Opts::get_records_opts(), Config::aws_config()) -> get_records_return()

DynamoDB Streams API: http://docs.aws.amazon.com/dynamodbstreams/latest/APIReference/API_GetRecords.html

Example

Get the records from a given shard iterator.

erlcloud_ddb_streams:get_records(<<"arn:aws:dynamodb:us-west-2:111122223333:table/Forum/stream/2015-05-20T20:51:10.252|1|AAAAAAAAAAEvJp6D+zaQ... <remaining characters omitted> ...">>). {ok, [#ddb_streams_record{ aws_region = <<"us-west-2">>, dynamodb = #ddb_streams_stream_record{ keys = [{<<"ForumName">>, <<"DynamoDB">>}, {<<"Subject">>, <<"DynamoDB Thread 3">>}], new_image = undefined, old_image = undefined, sequence_number = <<"300000000000000499659">>, size_bytes = 41, stream_view_type = keys_only}, event_id = <<"e2fd9c34eff2d779b297b26f5fef4206">>, event_name = insert, event_source = <<"aws:dynamodb">>, event_version = <<"1.0">>}, #ddb_streams_record{ aws_region = <<"us-west-2">>, dynamodb = #ddb_streams_stream_record{ keys = [{<<"ForumName">>, <<"DynamoDB">>}, {<<"Subject">>, <<"DynamoDB Thread 1">>}], new_image = undefined, old_image = undefined, sequence_number = <<"400000000000000499660">>, size_bytes = 41, stream_view_type = keys_only}, event_id = <<"4b25bd0da9a181a155114127e4837252">>, event_name = modify, event_source = <<"aws:dynamodb">>, event_version = <<"1.0">>}, #ddb_streams_record{ aws_region = <<"us-west-2">>, dynamodb = #ddb_streams_stream_record{ keys = [{<<"ForumName">>, <<"DynamoDB">>}, {<<"Subject">>, <<"DynamoDB Thread 2">>}], new_image = undefined, old_image = undefined, sequence_number = <<"500000000000000499661">>, size_bytes = 41, stream_view_type = keys_only}, event_id = <<"740280c73a3df7842edab3548a1b08ad">>, event_name = remove, event_source = <<"aws:dynamodb">>, event_version = <<"1.0">>}]}

get_shard_iterator/3

get_shard_iterator(StreamArn::stream_arn(), ShardId::shard_id(), ShardIteratorType::shard_iterator_type()) -> get_shard_iterator_return()

get_shard_iterator/4

get_shard_iterator(StreamArn::stream_arn(), ShardId::shard_id(), ShardIteratorType::shard_iterator_type(), Opts::get_shard_iterator_opts()) -> get_shard_iterator_return()

get_shard_iterator/5

get_shard_iterator(StreamArn::stream_arn(), ShardId::shard_id(), ShardIteratorType::shard_iterator_type(), Opts::get_shard_iterator_opts(), Config::aws_config()) -> get_shard_iterator_return()

DynamoDB API: http://docs.aws.amazon.com/dynamodbstreams/latest/APIReference/API_GetShardIterator.html

Example

Get a shard iterator.

erlcloud_ddb_streams:get_shard_iterator(<<"arn:aws:dynamodb:us-west-2:111122223333:table/Forum/stream/2015-05-20T20:51:10.252">>, <<"shardId-00000001414576573621-f55eea83">>, trim_horizon). {ok, <<"arn:aws:dynamodb:us-west-2:111122223333:table/Forum/stream/2015-05-20T20:51:10.252|1|AAAAAAAAAAEvJp6D+zaQ... <remaining characters omitted> ...">>}

list_streams/0

list_streams() -> list_streams_return()

list_streams/1

list_streams(Opts::list_streams_opts()) -> list_streams_return()

list_streams/2

list_streams(Opts::list_streams_opts(), Config::aws_config()) -> list_streams_return()

DynamoDB API: http://docs.aws.amazon.com/dynamodbstreams/latest/APIReference/API_ListStreams.html

Example

Get the list of streams with a limit of 3.

erlcloud_ddb_streams:list_streams([{limit, 3}]). {ok, [#ddb_streams_stream{ stream_arn = <<"arn:aws:dynamodb:us-west-2:111122223333:table/Forum/stream/2015-05-20T20:51:10.252">>, stream_label = <<"2015-05-20T20:51:10.252">>, table_name = <<"Forum">>}, #ddb_streams_stream{ stream_arn = <<"arn:aws:dynamodb:us-west-2:111122223333:table/Forum/stream/2015-05-20T20:50:02.714">>, stream_label = <<"2015-05-20T20:50:02.714">>, table_name = <<"Forum">>}, #ddb_streams_stream{ stream_arn = <<"arn:aws:dynamodb:us-west-2:111122223333:table/Forum/stream/2015-05-19T23:03:50.641">>, stream_label = <<"2015-05-19T23:03:50.641">>, table_name = <<"Forum">>}]}

new/2

new(AccessKeyID::string(), SecretAccessKey::string()) -> aws_config()

new/3

new(AccessKeyID::string(), SecretAccessKey::string(), Host::string()) -> aws_config()


Generated by EDoc