GithubHelp home page GithubHelp logo

ecoblockchain / aws_dynamo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from devicescape/aws_dynamo

0.0 2.0 0.0 538 KB

AWS DynamoDB Library for C and C++

License: GNU Lesser General Public License v3.0

Makefile 0.59% Shell 0.54% M4 0.34% C 98.53%

aws_dynamo's Introduction

aws_dynamo

AWS DynamoDB Library for C and C++

Features

  • Supports all DynamoDB operations (v1 and v2 protocols)
  • A flexible, efficient, and fast API for accessing DynamoDB from within C applications.
  • Supports obtaining AWS credentials from an IAM Role, environment variables or initialization parameters

Supported Systems

This library has been developed and tested on GNU/Linux. That said, this library attempts to be portable to wherever the dependacies listed below are available. Patches to increase portability or reports of portability successes or failures are appreciated.

Dependencies

Building

In addition to development headers for the libraries listed above the build depends on autoconf, automake, and libtool.

$ ./autogen.sh
$ ./configure
$ make

If you want to enable verbose debugging messages (this is only appropriate for development) then pass the '--enable-debug' option to 'configure'.

Then, to run tests:

$ make -j check

To install the library:

$ sudo make install

Basic Usage

For DynamoDB v2 support the library no longer provides an in-memory representation of the response. Instead, users of the library need to parse the JSON response on their own. See ./examples/v2-example.c

For v1 the library parses the response and creates an in-memory representation of the response.

See the examples/ subdirectory for detailed examples.

Get item attributes from DynamoDB. Assume we have a table named 'users' with a string hash key and attributes 'realName' and 'lastSeen'.

#define REAL_NAME_ATTRIBUTE_NAME	"realName"
#define REAL_NAME_ATTRIBUTE_INDEX	0
#define LAST_SEEN_ATTRIBUTE_NAME	"lastSeen"
#define LAST_SEEN_ATTRIBUTE_INDEX	1

	struct aws_handle *aws_dynamo;
	struct aws_dynamo_attribute attributes[] = {
		{
			/* Index: REAL_NAME_ATTRIBUTE_INDEX */
			.type = AWS_DYNAMO_STRING,
			.name = REAL_NAME_ATTRIBUTE_NAME,
			.name_len = strlen(REAL_NAME_ATTRIBUTE_NAME),
		},
		{
			/* Index: LAST_SEEN_ATTRIBUTE_INDEX */
			.type = AWS_DYNAMO_NUMBER,
			.name = LAST_SEEN_ATTRIBUTE_NAME,
			.name_len = strlen(LAST_SEEN_ATTRIBUTE_NAME),
			.value.number.type = AWS_DYNAMO_NUMBER_INTEGER,
		},
	};
	struct aws_dynamo_get_item_response *r = NULL;
	struct aws_dynamo_attribute *real_name;
	struct aws_dynamo_attribute *last_seen;

	const char *request = 
"{\
	\"TableName\":\"users\",\
	\"Key\":{\
		\"HashKeyElement\":{\"S\":\"jdoe\"}
	},\
	\"AttributesToGet\":[\""\
		REAL_NAME_ATTRIBUTE_NAME "\",\"" \
		LAST_SEEN_ATTRIBUTE_NAME \
	"\"]\
}";

	aws_dynamo = aws_init(aws_access_key_id, aws_secret_access_key);

	r = aws_dynamo_get_item(aws_dynamo, request, attributes, sizeof(attributes) / sizeof(attributes[0]));

	if (r == NULL) {
		return -1;
	}

	if (r->item.attributes == NULL) {
		/* No item found. */
		return;
	}

	real_name = &(r->item.attributes[REAL_NAME_ATTRIBUTE_INDEX]);
	last_seen = &(r->item.attributes[LAST_SEEN_ATTRIBUTE_INDEX]);

	/* prints: "John Doe was last seen at 1391883778." */
	printf("%s was last seen at %d.", real_name->value.string, last_seen->value.number.value.integer_val);

	aws_dynamo_free_get_item_response(r);

Notes

In all cases the caller is responsible for creating the request json. This requires some understanding of the AWS DynamoDB API. The v2 API is documented here:

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

As discussed above when the v2 API is used the caller is required to parse the JSON response.

Documentation for the v1 DynamoDB API can be found here:

http://aws.amazon.com/archives/Amazon-DynamoDB

See "Docs: Amazon DynamoDB (API Version 2011-12-05)"

See section, "Operations in Amazon DynamoDB" starting on page 331 for details on creating DynamoDB JSON requests.

In many cases the caller also provides a template for the structure where the response will be written. The then accesses the response attributes directly using known array indices.

The response json is parsed in all cases and returned to the caller in a C structure that must be free'd correctly when the caller is finished with it.

aws_dynamo's People

Contributors

dimastebaev avatar dkimdon avatar dtuttle avatar jbdatko avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.