DynamoDB

There is one call used to extract pieces of content from any response data.

createDynamoDBClient(String:accesskey, String:secret, String:region)

Creates a new client for AWS DynamoDB service. This client implements methods that uses AWS SDK 2 software.amazon.awssdk.services.dynamodb.DynamoDbClient.

Copy
if (typeof $accesskey == "undefined") {
    EncryptedHashDPL("EncryptedAWSCredentials.csv", "mysecretPassword123!");

var dynamoDB = createDynamoDBClient($accesskey, $secret, "us-west-2");

 

createTable(tableName, primaryKey, sortKey)

Creates a new table

Copy
dynamoDB.createTable("movies","movieName");

                                                

deleteTable(tableName)

deletes a Table.

Copy
client.deleteTable("movies-table");

 

hasTable(tableName)

Returns true if tableName exists.

Copy
if (client.hasTable($tableName)) {
    client.deleteAllItems($tableName,$key,$sort);
    client.deleteTable($tableName);
}

 

putItem(tableName, itemName)

Puts an item in the table.

Copy
var $myMoviesData = readCSV("{ds}/movies.csv");
var $types = ['s', 's', 's', 's', 's', 's', 's', 'n'];
client.putArrayData($myMoviesData, "movies", $types);

 

getItem(tableName, itemName, itemValue, [sortName], [sortValue])

Pulls an item from the table tableName. Can use only primary key or compound key with sort key.

Copy
client.putItem($tableName, lucaMovie.asItem());

 

updateItem(tableName, keyName,attributes)

Updates an item from the table tableName.

Copy
newValue = [{"attribute": "mykey", "type": "s", "value": "___key1"}];
newValue.push({"attribute": "fans", "type": "n", "value": 2});
newValue.push({"attribute": "map", "type": "m", "value": "{'Name': {'s': 'Joe'}, 'Age': {'s': '35'}}"});
newValue.push({"attribute": "checked", "type": "bool", "value": true});
client.updateItem("mytable", newValue);

 

deleteItem(tableName, keyValue)

Deletes an item from the table tableName.

Copy
client.deleteItem("mytable", "Luca");

 

deleteAllItems(tableName, partitionKey, sortKey)

Deletes all items from the table tableName.

Copy
client.deleteAllItems($tableName, $key, $sort);

 

queryFilter(tableName, filter)

Performs a filter on a table. This filter is implemented using queryRequest which in general is recommended over the filterScan method. Check this document for more references.

Copy
filter = {};
filter.names = [{"#Genre": "Genre"},{"#Year": "Year"}];
filter.values = [{":genre": "Drama", "type": "s"},{":year": 2008, "type": "n"}];
filter.keyCondition = "#Genre != :genre";
filter.filterExpression =  "#Year > :year"results = client.queryFilter("moviesByGenre", filter);
log("Filter Query : " + JSON.stringify(results));

 

filterScan(tableName, filter)

Performs a filter on a table. This filter is implemented using a ScanRequest method which might be slower and possibly generate bigger AWS costs than using queryFilter (see above). Check this document for more references.

Copy
filter = {};
filter.names = [{"#year": "year"}, {"#rating": "rating"}];
filter.values = [{":val1": "2016", "type": "n"}, {":val2": "****", "type": "s"}];
filter.expressions = ["#year >= :val1 AND #rating = :val2"];
results = client.filterScan("my-favorite-songs-table", filter);

 

putArrayData(String:tableName, String[][] data, String[]:attributeTypes)

Put a set of items read from a 2-dimensional string array into the table. The attributes types are specified as an array of characters.

Copy
var $myMoviesData = readCSV("{ds}/movies.csv");
var $types = ['s', 's', 's', 's', 's', 's', 's', 'n'];
client.putArrayData($myMoviesData, "movies", $types);