Dynamo
Reference doc for the `sst.aws.Dynamo` component.
The Dynamo
component lets you add an Amazon DynamoDB table to your app.
Minimal example
Add a global index
Optionally add a global index to the table.
Add a local index
Optionally add a local index to the table.
Subscribe to a DynamoDB Stream
To subscribe to a DynamoDB Stream, start by enabling it.
Then, subscribing to it.
Link the table to a resource
You can link the table to other resources, like a function or your Next.js app.
Once linked, you can query the table through your app.
Constructor
Parameters
-
name
string
-
args
DynamoArgs
-
opts?
ComponentResourceOptions
DynamoArgs
fields
Type Input
<
Record
<
string
, “
string
”
|
“
number
”
|
“
binary
”
>
>
An object defining the fields of the table that’ll be used to create indexes. The key is the name of the field and the value is the type.
While you can have fields field types other than string
, number
, and binary
; you can only use these types for your indexes.
globalIndexes?
Type Input
<
Record
<
string
, Input
<
Object
>
>
>
Configure the table’s global secondary indexes.
You can have up to 20 global secondary indexes per table. And each global secondary index should have a unique name.
globalIndexes[].hashKey
Type Input
<
string
>
The hash key field of the index. This field needs to be defined in the fields
.
globalIndexes[].rangeKey?
Type Input
<
string
>
The range key field of the index. This field needs to be defined in the fields
.
localIndexes?
Type Input
<
Record
<
string
, Input
<
Object
>
>
>
Configure the table’s local secondary indexes.
Unlike global indexes, local indexes use the same hashKey
as the primaryIndex
of the table.
You can have up to 5 local secondary indexes per table. And each local secondary index should have a unique name.
localIndexes[].rangeKey
Type Input
<
string
>
The range key field of the index. This field needs to be defined in the fields
.
primaryIndex
Type Input
<
Object
>
Define the table’s primary index. You can only have one primary index.
primaryIndex.hashKey
Type Input
<
string
>
The hash key field of the index. This field needs to be defined in the fields
.
primaryIndex.rangeKey?
Type Input
<
string
>
The hash key field of the index. This field needs to be defined in the fields
.
stream?
Type Input
<
“
keys-only
”
|
“
new-image
”
|
“
old-image
”
|
“
new-and-old-images
”
>
Default Not enabled
Enable DynamoDB Streams for the table.
When an item in the table is modified, the stream captures the information and sends it to your subscriber function.
You can configure what will be written to the stream:
new-image
: The entire item after it was modified.old-image
: The entire item before it was modified.new-and-old-images
: Both the new and the old items. A good default to use since it contains all the data.keys-only
: Only the keys of the fields of the modified items. If you are worried about the costs, you can use this since it stores the least amount of data.
transform?
transform.table?
ttl?
Type Input
<
string
>
The field of the table to store the Time to Live (TTL) timestamp in. This field should
be of type number
. When the TTL timestamp is reached, the item will be deleted.
Learn more about Time to Live (TTL).
Properties
arn
Type Output
<
string
>
The ARN of the DynamoDB Table.
name
Type Output
<
string
>
The name of the DynamoDB Table.
nodes
nodes.table
Type Output
<
Table
>
The Amazon DynamoDB Table.
SDK
The following are accessible through the SDK at runtime.
name
Type string
The name of the DynamoDB Table.
Methods
subscribe
Parameters
The function that’ll be notified.subscriber
string
|
FunctionArgs
Configure the subscription.args?
DynamoSubscriberArgs
Returns Output
<
DynamoLambdaSubscriber
>
Subscribe to the DynamoDB Stream of this table.
Add a filter to the subscription.
Customize the subscriber function.
static subscribe
Parameters
The ARN of the DynamoDB Stream to subscribe to.streamArn
Input
<
string
>
The function that’ll be notified.subscriber
string
|
FunctionArgs
Configure the subscription.args?
DynamoSubscriberArgs
Returns Output
<
DynamoLambdaSubscriber
>
Subscribe to the DynamoDB stream of a table that was not created in your app.
For example, let’s say you have a DynamoDB stream ARN of an existing table.
You can subscribe to it by passing in the ARN.
Add a filter to the subscription.
Customize the subscriber function.
DynamoSubscriberArgs
filters?
Type Input
<
Input
<
Record
<
string
, any
>
>
[]
>
Filter the records processed by the subscriber
function.
You can pass in up to 5 different filter policies. These will logically ORed together. Meaning that if any single policy matches, the record will be processed.
For example, if your DynamoDB table’s stream contains the follow record.
To process only those records where the CustomerName
is AnyCompany Industries
.
transform?
Type Object
Transform how this subscription creates its underlying resources.
transform.eventSourceMapping?
Type EventSourceMappingArgs
|
(
args
:
EventSourceMappingArgs
=>
void
)
Transform the Lambda Event Source Mapping resource.