
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
A simple wrapper library that simplifies using dynamoDB from Node.js.
Note: any run() method supports both callbacks and promises. If you don't pass a callback it will return a promise.
You write
new ammo.UpdateItem('movies')
.key({
year: 2015,
title: 'The Force Awakens'
})
.update('remove info.actors[0]')
.condition('size(info.actors) > :num', { ':num': 3 })
.returnConsumedCapacity('indexes')
.returnItemCollectionMetrics('size')
.returnValues('updated_new')
.run(function(err, data) {
if (err) {
console.error("Unable to update item. Error JSON:", JSON.stringify(err, null, 2))
} else {
console.log("UpdateItem succeeded:", JSON.stringify(data, null, 2))
}
})
Instead of writing
var params = {
"TableName": "movies",
"ExpressionAttributeValues": {
":num": {
"N": 3
}
},
"Key": {
"year": {
"N": 2015
},
"title": {
"S": "The Force Awakens"
}
},
"UpdateExpression": "remove info.actors[0]",
"ConditionExpression": "size(info.actors) > :num",
"ReturnConsumedCapacity": "INDEXES",
"ReturnItemCollectionMetrics": "SIZE",
"ReturnValues": "UPDATED_NEW"
}
dynamo.updateItem(params, function(err, data) {
if (err) {
console.error("Unable to update item. Error JSON:", JSON.stringify(err, null, 2))
} else {
console.log("UpdateItem succeeded:", JSON.stringify(data, null, 2))
}
});
npm install dynammo --save
## Usage
var AWS = require('aws-sdk')
var dynamo = new AWS.DynamoDB()
var ammo = require('dynammo')(dynamo, 'optional_prefix_')
// Available objects and methods:
new ammo.PutItem('table_name')...run(callback)
new ammo.UpdateItem('table_name')...run(callback)
new ammo.DeleteItem('table_name')...run(callback)
new ammo.GetItem('table_name')...run(callback)
new ammo.Query('table_name')...run(callback)
new ammo.Scan('table_name')...run(callback)
The optional prefix will be used in all table and index names. This is useful if you have multiple apps using the same AWS account. This way you can use a prefix per app and you don't have naming collisions.
Some methods allow you to specify an expression like this:
query.condition('#y = :year and title = :title',
{ ':year': 2015, ':title': 'The Force Awakens' },
{ '#y': 'year' }
)
In this case we are querying items with a given year and title value. To pass the values we need to use a placeholder in the expression (:year and :title) and specify the values for these placeholders in the second parameter of the method condition(). In this case:
{ ':year': 2015, ':title': 'The Force Awakens' }
But we are passing also third argument. Why? Because our condition should have been year = :year and title = :title but year is a reserved keyword so we cannot use year directly in the expression. Instead we use the #y placeholder and in the third parameter we specify the actual name of that attribute. In the example:
{ '#y': 'year' }
Example:
new ammo.PutItem('table_name')
.item({
year: 2015,
title: 'The Force Awakens',
genre: 'Science fiction',
score: 8,
})
.returnConsumedCapacity('indexes')
.returnItemCollectionMetrics('size')
.returnValues('none')
.run(function(err, res) {
// res.raw contains the raw AWS response
// res.attributes will be defined depending on returnValues()
})
Methods
item(object) (required) allows you to set all the attributes for the object. Both keys and non-keys attributesreturnConsumedCapacity(string) allowed values are INDEXES, TOTAL or NONE (case insensitive)returnItemCollectionMetrics(string) allowed values are SIZE or NONE (case insensitive)returnValues(string) allowed values are NONE, ALL_OLD, UPDATED_OLD, ALL_NEW, UPDATED_NEW (case insensitive)condition(condition[, values[, names]])params() returns the params object that would be passed to the AWS SDKrun(callback) invokes the putItem() method in the AWS SDKExample:
new ammo.UpdateItem('table_name')
.key({
year: 2015,
title: 'The Force Awakens'
})
.update('set score = :score', { ':score': 10 })
.condition('score = :num', { ':num': 3 })
.returnConsumedCapacity('indexes')
.returnItemCollectionMetrics('size')
.returnValues('updated_new')
.run(function(err, res) {
// res.raw contains the raw AWS response
// res.attributes will be defined depending on returnValues()
})
Methods
key(object) (required) allows you to specify the key attributes of the object to be updatedupdate(expression[, values[, names]]) allows you to specify the attributes to be updatedreturnConsumedCapacity(string) allowed values are INDEXES, TOTAL or NONE (case insensitive)returnItemCollectionMetrics(string) allowed values are SIZE or NONE (case insensitive)returnValues(string) allowed values are NONE, ALL_OLD, UPDATED_OLD, ALL_NEW, UPDATED_NEW (case insensitive)condition(condition[, values[, names]]) allows you to specify a condition. If the condition is evaluated to true amazon won't update the objectparams() returns the params object that would be passed to the AWS SDKrun(callback) invokes the updateItem() method in the AWS SDKExample:
new ammo.DeleteItem('table_name')
.key({
year: 2015,
title: 'The Force Awakens',
})
.returnConsumedCapacity('indexes')
.returnItemCollectionMetrics('size')
.returnValues('none')
.condition('score = :score', { ':score': 3 })
.run(function(err, res) {
// res.raw contains the raw AWS response
// res.attributes will be defined depending on returnValues()
})
Methods
key(object) (required) allows you to specify the key attributes of the object to be deletedreturnConsumedCapacity(string) allowed values are INDEXES, TOTAL or NONE (case insensitive)returnItemCollectionMetrics(string) allowed values are SIZE or NONE (case insensitive)returnValues(string) allowed values are NONE, ALL_OLD, UPDATED_OLD, ALL_NEW, UPDATED_NEW (case insensitive)condition(condition[, values[, names]]) allows you to specify a condition. If the condition is evaluated to true amazon won't delete the objectparams() returns the params object that would be passed to the AWS SDKrun(callback) invokes the deleteItem() method in the AWS SDKExample:
new ammo.GetItem(tableName)
.key({
year: 2015,
title: 'The Force Awakens',
})
.returnConsumedCapacity('indexes')
.consistentRead(true)
.run(function(err, res) {
// res.raw contains the raw AWS response
// res.item contains the desired item
})
Methods
select(string) (required) allows you to specify the key attributes of the object to be readconsistentRead(boolean) allows you to specify the consistent read constraintreturnConsumedCapacity(string) allowed values are INDEXES, TOTAL or NONE (case insensitive)params() returns the params object that would be passed to the AWS SDKrun(callback) invokes the getItem() method in the AWS SDKExample:
new ammo.Query('table_name')
.select('*')
.consistentRead(false)
.condition('#y = :year and title = :title',
{ ':year': 2015, ':title': 'The Force Awakens' },
{ '#y': 'year' }
)
.returnConsumedCapacity('indexes')
.run(function(err, res) {
// res.raw contains the raw AWS response
// res.items contains the items found
})
Methods
select(string) (required) allowed values are ALL_ATTRIBUTES, ALL_PROJECTED_ATTRIBUTES, SPECIFIC_ATTRIBUTES, COUNT (case insensitive). * is an alias of ALL_ATTRIBUTEScondition(condition[, values[, names]]) (required) specifies the condition of the queryexclusiveStartKey(object) for paginated results it allows you to specify the key of the last object read in the previous pageindexName(string) allows you to specify the index to usefilter(expression) filters the returned values matching that expressionlimit(number) specifies the maximum number of objects to returnforward(boolean) specifies the orderingconsistentRead(boolean) allows you to specify the consistent read constraintreturnConsumedCapacity(string) allowed values are INDEXES, TOTAL or NONE (case insensitive)params() returns the params object that would be passed to the AWS SDKrun(callback) invokes the getItem() method in the AWS SDKExample:
new ammo.Scan('table_name')
.select('*')
.consistentRead(false)
.returnConsumedCapacity('indexes')
.run(function(err, res) {
// res.raw contains the raw AWS response
// res.items contains the items found
})
Methods
select(string) (required) allowed values are ALL_ATTRIBUTES, ALL_PROJECTED_ATTRIBUTES, SPECIFIC_ATTRIBUTES, COUNT (case insensitive). * is an alias of ALL_ATTRIBUTESexclusiveStartKey(object) for paginated results it allows you to specify the key of the last object read in the previous pageindexName(string) allows you to specify the index to usefilter(expression) filters the returned values matching that expressionlimit(number) specifies the maximum number of objects to returnsegment(number) specifies the segment to processtotalSegments(number) specifies the total segments to be processedforward(boolean) specifies the orderingconsistentRead(boolean) allows you to specify the consistent read constraintreturnConsumedCapacity(string) allowed values are INDEXES, TOTAL or NONE (case insensitive)params() returns the params object that would be passed to the AWS SDKrun(callback) invokes the getItem() method in the AWS SDKTests expect to have dynamodb running locally and will create and destroy a table called dynammo_movies.
FAQs
Wrapper for dynamoDB and node
We found that dynammo demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.