Skip to content

Commit a3555f4

Browse files
committed
revamp ddb streams
1 parent 52b93bb commit a3555f4

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

src/content/docs/aws/services/dynamodbstreams.md

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The stream records are written to a DynamoDB stream, which is an ordered flow of
1111
DynamoDB Streams records data in near-real time, enabling you to develop workflows that process these streams and respond based on their contents.
1212

1313
LocalStack supports DynamoDB Streams, allowing you to create and manage streams in a local environment.
14-
The supported APIs are available on our [DynamoDB Streams coverage page]({{< ref "coverage_dynamodbstreams" >}}), which provides information on the extent of DynamoDB Streams integration with LocalStack.
14+
The supported APIs are available on our [DynamoDB Streams coverage page](), which provides information on the extent of DynamoDB Streams integration with LocalStack.
1515

1616
## Getting started
1717

@@ -30,14 +30,14 @@ We will demonstrate the following process using LocalStack:
3030
You can create a DynamoDB table named `BarkTable` using the [`CreateTable`](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_CreateTable.html) API.
3131
Run the following command to create the table:
3232

33-
{{< command >}}
34-
$ awslocal dynamodb create-table \
33+
```bash
34+
awslocal dynamodb create-table \
3535
--table-name BarkTable \
3636
--attribute-definitions AttributeName=Username,AttributeType=S AttributeName=Timestamp,AttributeType=S \
3737
--key-schema AttributeName=Username,KeyType=HASH AttributeName=Timestamp,KeyType=RANGE \
3838
--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 \
3939
--stream-specification StreamEnabled=true,StreamViewType=NEW_AND_OLD_IMAGES
40-
{{< /command >}}
40+
```
4141

4242
The `BarkTable` has a stream enabled which you can trigger by associating a Lambda function with the stream.
4343
You can notice that in the `LatestStreamArn` field of the response:
@@ -79,17 +79,17 @@ exports.handler = (event, context, callback) => {
7979
You can now create a Lambda function using the [`CreateFunction`](https://docs.aws.amazon.com/lambda/latest/dg/API_CreateFunction.html) API.
8080
Run the following command to create the Lambda function:
8181
82-
{{< command >}}
83-
$ zip index.zip index.js
84-
$ awslocal lambda create-function \
82+
```bash
83+
zip index.zip index.js
84+
awslocal lambda create-function \
8585
--function-name publishNewBark \
8686
--zip-file fileb://index.zip \
8787
--role roleARN \
8888
--handler index.handler \
8989
--timeout 50 \
9090
--runtime nodejs16.x \
9191
--role arn:aws:iam::000000000000:role/lambda-role
92-
{{< /command >}}
92+
```
9393
9494
### Invoke the Lambda function
9595
@@ -138,12 +138,12 @@ Create a new file named `payload.json` with the following content:
138138
139139
Run the following command to invoke the Lambda function:
140140
141-
{{< command >}}
142-
$ awslocal lambda invoke \
141+
```bash
142+
awslocal lambda invoke \
143143
--function-name publishNewBark \
144144
--payload file://payload.json \
145145
--cli-binary-format raw-in-base64-out output.txt
146-
{{< /command >}}
146+
```
147147
148148
In the `output.txt` file, you should see the following output:
149149
@@ -157,20 +157,20 @@ To add the DynamoDB stream as an event source for the Lambda function, you need
157157
You can get the stream ARN using the [`DescribeTable`](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DescribeTable.html) API.
158158
Run the following command to get the stream ARN:
159159
160-
{{< command >}}
160+
```bash
161161
awslocal dynamodb describe-table --table-name BarkTable
162-
{{< /command >}}
162+
```
163163
164164
You can now create an event source mapping using the [`CreateEventSourceMapping`](https://docs.aws.amazon.com/lambda/latest/dg/API_CreateEventSourceMapping.html) API.
165165
Run the following command to create the event source mapping:
166166
167-
{{< command >}}
167+
```bash
168168
awslocal lambda create-event-source-mapping \
169169
--function-name publishNewBark \
170170
--event-source arn:aws:dynamodb:us-east-1:000000000000:table/BarkTable/stream/2024-07-12T06:18:37.101 \
171171
--batch-size 1 \
172172
--starting-position TRIM_HORIZON
173-
{{< /command >}}
173+
```
174174
175175
Make sure to replace the `event-source` value with the stream ARN you obtained from the previous command.
176176
You should see the following output:
@@ -189,11 +189,11 @@ You should see the following output:
189189
You can now test the event source mapping by adding an item to the `BarkTable` table using the [`PutItem`](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_PutItem.html) API.
190190
Run the following command to add an item to the table:
191191
192-
{{< command >}}
193-
$ awslocal dynamodb put-item \
192+
```bash
193+
awslocal dynamodb put-item \
194194
--table-name BarkTable \
195195
--item Username={S="Jane Doe"},Timestamp={S="2016-11-18:14:32:17"},Message={S="Testing...1...2...3"}
196-
{{< /command >}}
196+
```
197197
198198
You can find Lambda function being triggered in the LocalStack logs.
199199
@@ -202,9 +202,9 @@ You can find Lambda function being triggered in the LocalStack logs.
202202
You can list the streams using the [`ListStreams`](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_ListStreams.html) API.
203203
Run the following command to list the streams:
204204
205-
{{< command >}}
205+
```bash
206206
awslocal dynamodbstreams list-streams
207-
{{< /command >}}
207+
```
208208
209209
The following output shows the list of streams:
210210
@@ -223,8 +223,9 @@ The following output shows the list of streams:
223223
You can also describe the stream using the [`DescribeStream`](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DescribeStream.html) API.
224224
Run the following command to describe the stream:
225225
226-
{{< command >}}
227-
$ awslocal dynamodbstreams describe-stream --stream-arn arn:aws:dynamodb:us-east-1:000000000000:table/BarkTable/stream/2024-07-12T06:18:37.101
228-
{{< /command >}}
226+
```bash
227+
awslocal dynamodbstreams describe-stream \
228+
--stream-arn arn:aws:dynamodb:us-east-1:000000000000:table/BarkTable/stream/2024-07-12T06:18:37.101
229+
```
229230
230231
Replace the `stream-arn` value with the stream ARN you obtained from the previous command.

0 commit comments

Comments
 (0)