Security News
UK Officials Consider Banning Ransomware Payments from Public Entities
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
@jupiterone/dynamodb-dao
Advanced tools
This project contains code for a DynamoDbDao
class that can be used for
creating, querying, updating, and deleting from DynamoDB table. Unlike tools
like dynamoose
, DynamoDbDao
is a lower level wrapper and aims not to
abstract away too many of the DynamoDB implementation details.
Also, this module leverages TypeScript type declarations so that, when possible, methods arguments and return values are strictly typed.
Constructor:
import AWS from 'aws-sdk';
import DynamoDbDao from '@jupiterone/dynamodb-dao';
const dynamodb = new AWS.DynamoDB({
apiVersion: '2012-08-10'
});
const documentClient = new AWS.DynamoDB.DocumentClient({
service: dynamodb
});
// The type declaration of for the documents that we are storing
interface MyDocument {
id: string;
accountId: string;
name: string;
total?: number;
}
// Key schema should have one or two properties which correspond to
// hash key and range key.
//
// NOTE: a range key is optional and depends
// on how your DynamoDB table is configured.
interface MyDocumentKeySchema {
// hash key
accountId: string;
// range key
id: string;
}
const myDocumentDao = new DynamoDbDao<MyDocument, MyDocumentKeySchema>({
tableName: 'my-documents',
documentClient
});
Get query:
const myDocument = await myDocumentDao.get({ id, accountId });
Paginated query:
const { items, lastKey } = await myDocumentDao.query({
index: 'NameIndex',
keyConditionExpression: 'accountId = :accountId',
startAt: cursor /* `cursor` is a previously returned `lastKey` */,
scanIndexForward: true,
attributeValues: {
':accountId': accountId,
},
});
Count query:
const count = await myDocumentDao.count({
index: 'NameIndex',
keyConditionExpression: 'accountId = :accountId',
attributeValues: {
':accountId': input.accountId,
},
});
Put:
await myDocumentDao.put({
id: 'something',
accountId: 'abc'
name: 'blah'
});
Delete:
await myDocumentDao.delete({ id, accountId });
Incrementing/Decrementing
NOTE: This should only be used where overcounting and undercounting can be tolerated. See the DynamoDB atomic counter documentation for more information.
If a property does not already exist, the initial value is assigned 0
and
incremented/decremented from 0
.
// `total` will have the value `5`
const { total } = await myDocumentDao.incr(
// The key
{
id: 'abc',
accountId: 'def',
},
// The `number` property to increment
'total',
// The number to increment by. Defaults to 1.
5,
);
// `total` will have the value `-5`
const { total } = await myDocumentDao.decr(
// The key
{
id: '123',
accountId: 'def',
},
// The `number` property to increment
'total',
// The number to decrement by. Defaults to 1.
5,
);
The test setup requires that docker-compose be installed. To run the tests, first open one terminal and start the local DynamoDB docker container by running:
yarn start:containers
In a second terminal run:
yarn test
To stop containers:
yarn stop:containers
FAQs
DynamoDB Data Access Object (DAO) helper library
The npm package @jupiterone/dynamodb-dao receives a total of 1,161 weekly downloads. As such, @jupiterone/dynamodb-dao popularity was classified as popular.
We found that @jupiterone/dynamodb-dao demonstrated a healthy version release cadence and project activity because the last version was released less than 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
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.