- The DynamoDb API is secured by an API Gateway Cognito Authorizer
- A Cognito ID token is required as a Bearer token in the Authorization header
- Go to DynamoDb API webpage to copy your ID token to use with Postman
/endpoint?table=TableAlias&id=1
- The
table
querystring parameter is required - The value of the
table
querystring parameter should be the TableAlias the AdminAPI has mapped to the actual DynamoDb table name. i.e.Workers: ttd-Workers
whereWorkers
is the TableAlias - The AdminAPI has a map of all the TableAlias values as well as the primary/partition key names for the corresponding DynamoDb tables
- The
id
querystring parameter is optional depending on the request type - The value of the
id
querystring parameter should be the primary/partition key for the record in the table to act on - The
id
querystring parameter is used regardless of the name of the primary/partition key of the table
{
GET: `get`, // get | list
POST: `create`, // create | scan
PUT: `update`,
DELETE: `delete`,
OPTIONS: `options`
}
- If the HTTP method is
GET
and there is anid
querystring parameter, theget()
method will be executed, if theid
querystring parameter is not present then thelist()
method will be executed. - If the HTTP method is
POST
and there is anaction
querystring parameter with valuescan
thescan()
method will be executed, if not thecreate()
method will be executed.
/endpoint?table=TableAlias
- If the primary/partition key is included in the payload the supplied value will be used.
- This allows the requestor to specify the value to use for the primary/partition key
- This allows you to overwrite/replace the entire record with a new object
- If the primary/partition key is not supplied, the AdminAPI will auto-generate one using uuidv4
- The following properties will be auto-generated
created: now.toISOString(),
createdBy: identity,
lastUpdatedBy: identity,
lastUpdatedDateTime: now.toISOString()
- The identity listed above will come from Cognito
let identity = identity = event.requestContext.authorizer.claims[`custom:username`];
identity = identity.split(`.`).reverse().join(`, `);
- The response will contain the newly created item containing all the auto-generated properties
{ success: true, item: data }
/endpoint?table=TableAlias&id=1
- Returns the item from the specified table by primary/partition key
// statusCode 200
{ success: true, item: data }
// statusCode 404
{
success: false,
error: `Item not found.`
}
/endpoint?table=TableAlias
- No
id
querystring parameter - Returns all records in the specified table
- table=Workers
- paginate=true
- LastEvaluatedKey=%7B%22empId%22%3A%22110741%22%7D //
${encodeURIComponent(JSON.stringify({"empId": "110741"}))}
- Returns an array on success
- If paginate is true then returns an Object
- JSON Object on error
// statusCode 200
[]
// statusCode 200 with paginate specified
{
"Items": [],
"Count": 0,
"ScannedCount": 60,
"LastEvaluatedKey": {
"empId": "352846"
}
}
// statusCode 400
{
success: false,
error
}
/endpoint?table=TableAlias&action=scan
- Scans the specified table based on the supplied payload
- Supports dot-notation for updating nested values
- Use
attributesToGet
to return a subset of properties from the records
- Required to have a
scan
property - Optionally contains an
attributesToGet
property
{
"scan": {},
"attributesToGet": [],
"paginate": true,
"LastEvaluatedKey": {
"empId": "352846"
}
}
- The
scan
object may contain the following keywordsattributesExist
attributesNotExist
- Arrays
- If the value of the specified attribute is a string array
OR
logic will be applied - If the value of the specified attribute is an array of string arrays,
OR
logic will be applied within the arrays andAND
logic applied between arrays
- If the value of the specified attribute is a string array
// colors array contains red OR blue
{
"scan": {
"colors": ["red","blue"]
}
}
- Same effect as above
// colors array contain red OR blue
{
"scan": {
"colors": [["red","blue"]]
}
}
// colors array contains (red OR pink) AND blue
// colors array contains (red and blue) or (pink and blue)
{
"scan": {
"colors": [["red", "pink"],["blue"]]
}
}
- JSON Objects
- If the value of the specified attribute is a JSON Object the AdminAPI will expect a
comparator
andvalue
property on the object
- If the value of the specified attribute is a JSON Object the AdminAPI will expect a
{
"scan": {
"total": {
"comparator": "<",
"value": 100
}
}
}
{
"attributesToGet": ["worker"],
"scan": {
"worker.empGroupIds": [["-989357139129.0"],["-988766726027.0"]],
"training.status": ["completed", "timelimitmet"],
"training.isActive": "1",
"attributesNotExist": [
"training.timeOfCompletion"
],
"dueDays": {
"comparator": "<=",
"value": "10"
}
}
}
// statusCode 200
[]
// statusCode 200 with paginate specified
{
"Items": [],
"Count": 0,
"ScannedCount": 60,
"LastEvaluatedKey": {
"empId": "352846"
}
}
// statusCode 400
{
success: false,
error
}
/endpoint?table=TableAlias&id=1
- Updates the specified properties for the item specified by the primary/partition key in the specified table
- Payload must contain one of the following allowed actions
- set
- remove
- add
- delete
- setListAppend
{
"set": {},
"remove": {},
"add": {},
"delete": {},
"setListAppend": {}
}
- Any combination of the above actions can be present in the payload
- All actions support dot-notation for updating nested values
- Updates the values stored at the specified keys
- Remove the property from the record
- Increment the value stored at the specified keys
- Removing elements from a set
- The DELETE action supports only Set data types.
- Push the specified values to the list/array stored at the specified keys
{
"set":{
"training.status": "timelimitmet"
},
"add":{
"training.timeInTraining": 180000
},
"setListAppend": {
"training.taskSids": ["WT1e33bd86f2b02bd941b07460e3a984e6","WT23f871f71f44752a3f14ea3e9349e253"]
}
}
- The update response will contain a
results
property containing the result of all the actions included in the update. - Some actions may succeed while others fail. A statusCode of 400 will be returned with a
results
array so you can determine which actions succeed or failed.
// statusCode 200
{ success: true, results }
// statusCode 400
{ success: false, results }
// statusCode 400
{
success: false,
error
}
/endpoint?table=TableAlias&id=1
- Deletes the item from the specified table by primary/partition key
// statusCode 200
{ success: true }
// statusCode 400
{
success: false,
error
}
/endpoint?table=TableAlias&id=1
- For CORS pre-flight requests
// statusCode 200
{ success: true }