Basic Request
--require module
local db = require('dynamodb.client')
--initialize
db:init({
aws_key = "<AWS access key>",
aws_secret = "<AWS secret key">,
aws_region = "us-east-1",
debug = true
})
--build request payload
local payload =
{
TableName = "Music",
Key =
{
Artist = db:S("The Acme Band"),
SongTitle = db:S("Look Out, World")
}
}
--set up listener
function dbEventListener( evt )
if evt.error then
print(evt.reason, evt.status)
else
local data_table = evt.result --Lua table
end
end
--add event listener
db.events:addEventListener( "DynamoDBEvent", dbEventListener )
--make DynamoDB request
db:request("GetItem", payload)
See also: Attribute Type Methods.
Payloads
For full payload parameters and usage see the included links.
Important
When viewing the DynamoDB API Documentation, all payloads for DynamoDB are shown using JSON notation. You will need to convert the JSON stylings to Lua table structures. If you'd rather construct payloads using JSON, then be sure to json.encode()
your payload before making a request.
All examples below are shown using Lua table structures, which have been converted from JSON.
GetItem
http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_GetItem.html
{
TableName = "Music",
Key =
{
Artist = db:S("The Acme Band"),
SongTitle = db:S("Look Out, World")
}
}
PutItem
http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_PutItem.html
{
TableName = "Music",
Item =
{
Artist = db:S("No One You Know"),
SongTitle = db:S("The Best Song Ever"),
Rating = db:N(5)
}
}
UpdateItem
http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_UpdateItem.html
{
TableName = "Music",
Key = {
Artist = db:S("No One You Know"),
SongTitle = db:S("The Best Song Ever")
},
UpdateExpression = "SET Rating = :val1",
ConditionExpression = "Rating < :val2",
ExpressionAttributeValues =
{
[":val1"] = db:N(10),
[":val2"] = db:N(10)
},
ReturnValues = "ALL_NEW"
}
DeleteItem
http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DeleteItem.html
{
TableName = "Music",
Key =
{
Artist = db:S("The Acme Band"),
SongTitle = db:S("Still In Love")
}
}
Scan
http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Scan.html
{
TableName = "Music"
}
Query
http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html
{
TableName = "Music",
KeyConditionExpression = "Artist = :val1",
ExpressionAttributeValues =
{
[":val1"] = db:S("No One You Know")
}
}
CreateTable
http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_CreateTable.html
{
TableName = "Library",
KeySchema =
{
{
AttributeName = "Book",
KeyType = "HASH"
}
},
AttributeDefinitions =
{
{
AttributeName = "Book",
AttributeType = "S"
}
},
ProvisionedThroughput =
{
ReadCapacityUnits = 5,
WriteCapacityUnits = 5
}
}
ListTables
http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_ListTables.html
{
Limit = 5
}
DescribeTable
http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DescribeTable.html
{
TableName = "Music"
}
DeleteTable
http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DeleteTable.html
{
TableName = "Library"
}
BatchGetItem
http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchGetItem.html
{
RequestItems =
{
Music =
{
Keys =
{
{
Artist = db:S("No One You Know"),
SongTitle = db:S("Call Me Today")
},
{
Artist = db:S("The Acme Band"),
SongTitle = db:S("Look Out, World")
}
},
ProjectionExpression = "SongTitle"
},
Library =
{
Keys =
{
{
Book = db:S("A Tale Of Three Eyes")
}
}
}
},
ReturnConsumedCapacity = "TOTAL"
}
BatchWriteItem
http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchWriteItem.html
{
RequestItems =
{
Library =
{
{
PutRequest =
{
Item =
{
Book = db:S("1000 Degrees In The Sun")
}
}
}
},
Music =
{
{
DeleteRequest =
{
Key =
{
Artist = db:S("The Acme Band"),
SongTitle = db:S("Look Out, World")
}
}
},
{
DeleteRequest =
{
Key =
{
Artist = db:S("No One You Know"),
SongTitle = db:S("My Dog Spot")
}
}
}
}
},
ReturnConsumedCapacity = "TOTAL"
}