DYNAMODB Library

DYNAMODB Library

The DYNAMODB Library is an importable library containing functions to read, write, and list with AWS DynamoDB tables. This library is used in the AWS DynamoDB Adapter .

When imported into projects, typically only the DYNAMODBclient module needs to be required in order to create the client and access the API methods.

require "DYNAMODB.DYNAMODBclient"

How it works:

Use the Translator’s built in help to review how to use each function.

Key Functions and Methods:

Sets up the DYNAMODB adapter framework, adding the various method modules to a metatable and storing the configurations added to the custom fields.

DYNAMODBcustom takes in any API requests and parameters to make the API call and return the response.

  • Uses the passed configurations API request parameters - the action (ex. GetItem) and the data (ex. JSON string of the input parameters) - to build and carry out the appropriate HTTP request.

DYNAMODBdeleteItem prepares the arguments and calls DYNAMODBcustom for a DynamoDB DeleteItem API request.

DYNAMODBdeleteItem prepares the arguments and calls DYNAMODBcustom for a DynamoDB GetItem API request.

DYNAMODBdeleteItem prepares the arguments and calls DYNAMODBcustom for a DynamoDB DynamoDB API request.

DYNAMODBdeleteItem prepares the arguments and calls DYNAMODBcustom for a DynamoDB Query API request.

DYNAMODBdeleteItem prepares the arguments and calls DYNAMODBcustom for a DynamoDB UpdateItem API request.

Utility Functions:

DYNAMODBgetHeaders generates headers for each HTTP request.

  • authorization - generated based on the payload, canonical endpoint, and method, then signed with IAM user credentials. This header is used with every request type.

  • content-type - content type of the data in the HTTP request.

DYNAMODBcreateAssgnExp creates a DynamoDB assignment expression. It takes a given table of inputs, identifies the attributes, and returns a DynamoDB formatted assignment expression where the attributes are assigned to placeholder equivalents. For example, ID will be returned as ID = :ID.

DYNAMODBcreateExpMap creates a DynamoDB expression map. It takes a given table of inputs, identifies the attributes, and returns a DynamoDB formatted expression where the attributes are mapped to placeholder equivalents. For example, ID will be returned as ID :ID.

DYNAMODBcreateAttrValue creates a DynamoDB AttributeValue table. It takes a given value, identifies the AttributeValue (aka the DynamoDB version of data type), and returns the value as a DynamoDB AttributeValue table. For example, {value='123'} would be returned as {['S'] = '123'}.

DYNAMODBcreateItemMap creates a DynamoDB item map. It takes a given table of inputs, identifies the attributes and their target values, and dynamically attempts to identify the AttributeValue type of the attributes. It then applies DYNAMODBcreateAttrValue to format each attribute’s value in AttributeValue structure and returns a map of the entire list of attributes with their target values as AttributeValues. For example, {ID = '123', Active = true} will be returned as {ID = {['S'] = '123'}, Active = {['BOOL'] = true}}.

AttributeValues that can be identified include:

  • string (S)

  • number (N)

  • binary (B)

  • boolean (BOOL)

  • null (NULL)

  • list (L)

  • map (M)

  • stringSet (SS)

  • numberSet (NS)

  • binarySet (BS)

Otherwise, the type can be manually specified via the type parameter.

DYNAMODBcreateExpValue creates a DynamoDB expression value. It takes a given table of inputs, identifies the attributes, and uses DYNAMODBcreateItemMap to generate a map of the attributes' placeholders with their given values in AttributeValue format. For example, {ID = '123', Active = true} will be returned as {[':ID'] = {['S'] = '123'}, [':Active'] = {['BOOL'] = true}}.

A local version of ENCRYPT Library is also included for securing the API access token.