AWS DynamoDB Adapter
Need help? Contact us:
The AWS DynamoDB adapter is a simple component which can be used to interact with AWS DynamoDB tables and their items. The adapter provides functionality to get, put, update, delete, and query items in a table.
This component assumes an AWS IAM user has been set up with the correct permissions to interact with the DynamoDB table(s).
How to use it:
STEP 1: Import the AWS DynamoDB Adapter component in Iguana
See Create a Component if this is your first time!
STEP 2: Configure the AccessKey, PrivateKey, Region and BucketName custom fields and click Edit to open the Translator
Enter your AWS IAM user's AccessKey and SecretKey, as well as the DynamoDB's Region. If you already have a DynamoDB table, fill in the TableName too. AWS documentation for creating AccessKey - SecretKey pairs
Using the information provided, the component will create a DynamoDB adapter object that can be used to interact with your table.
![]()
STEP 3 (OPTIONAL): Create a DynamoDB table via the UI or programmatically in the Translator.
If you didn't create a DynamoDB table yet, you can do so via the UI or via the sample code in the Translator. Uncomment the code to create the table, set live = true, let the annotations run once, then re-comment the code or set live = false to ensure you don't attempt to create the table multiple times.
-- Create our adapter
local Configs = component.fields()
local DDB = DYNAMODBclient{
AccessKey = Configs.AccessKey,
SecretKey = Configs.SecretKey,
Region = Configs.Region
}
-- Optionally uncomment the below to create the table programmatically
-- Make sure to re-comment the code afterwards to avoid creating multiple tables
--[[local Create = {
TableName = 'Patients',
AttributeDefinitions = {{
AttributeName = "ID",
AttributeType = "S"}
},
KeySchema = {{
AttributeName = "ID",
KeyType = "HASH"}
},
BillingMode = 'PAY_PER_REQUEST'
}
-- Set live = true to run the operation once, then set back to false
DDB:custom{action = 'CreateTable',data=json.serialize{data=Create},live=false}]]
STEP 4: View and modify the examples for uploading, reading and listing objects in an S3 bucket.
Use the provided sample data to put or update sample json data into your DynamoDB table. You can add samples via the Samples folder. Set live=true to enable the interaction from the Translator.
Get the item (if it exists) from the table:
-- Parse the inbound data
local PatientData = json.parse{data=Data}
-- Check if the item already exists
local Status, Item = D:getItem{
table_name = Configs.TableName,
key = PatientData.id,
live = true
}
Now update the item if it exists or create it and put it into the table if it doesn't:
-- Create or update the item
if next(Item) then
-- Update the item
D:updateItem{
table_name = Configs.TableName,
key = PatientData.id,
set = {
Active = true,
Facility = 'Hospital',
},
live = true
}
else
-- Create an item
D:putItem{
table_name = Configs.TableName,
item = {
ID = PatientData.id,
FullName = PatientData.name,
DOB = PatientData.dob,
Address = {
Street = PatientData.address,
City = PatientData.city,
Zip = PatientData.zip
}
},
live = true
}
end
You can also play around with the deleteItem and query methods using the built-in help details.