serverless-spy
Version:
CDK-based library for writing elegant integration tests on AWS serverless architecture and an additional web console to monitor events in real time.
51 lines (39 loc) • 1.46 kB
Markdown
# @aws-sdk/util-dynamodb
[](https://www.npmjs.com/package/@aws-sdk/util-dynamodb)
[](https://www.npmjs.com/package/@aws-sdk/util-dynamodb)
This package provides utilities to be used with `@aws-sdk/client-dynamodb`
If you are looking for DynamoDB Document client, please check
[@aws-sdk/lib-dynamodb](https://www.npmjs.com/package/@aws-sdk/lib-dynamodb)
which automatically performs the necessary marshalling and unmarshalling.
## Convert JavaScript object into DynamoDB Record
```js
const { DynamoDB } = require("@aws-sdk/client-dynamodb");
const { marshall } = require("@aws-sdk/util-dynamodb");
const client = new DynamoDB(clientParams);
const params = {
TableName: "Table",
Item: marshall({
HashKey: "hashKey",
NumAttribute: 1,
BoolAttribute: true,
ListAttribute: [1, "two", false],
MapAttribute: { foo: "bar" },
NullAttribute: null,
}),
};
await client.putItem(params);
```
## Convert DynamoDB Record into JavaScript object
```js
const { DynamoDB } = require("@aws-sdk/client-dynamodb");
const { marshall, unmarshall } = require("@aws-sdk/util-dynamodb");
const client = new DynamoDB(clientParams);
const params = {
TableName: "Table",
Key: marshall({
HashKey: "hashKey",
}),
};
const { Item } = await client.getItem(params);
unmarshall(Item);
```