Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/serverless-offline-dynamodb-streams/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,13 @@ functions:
type: dynamodb
tableName: myTable
```

### Retries

By default if function fails it will be invoked in a loop until it succeeds. You can specify a finite number of retries instead:

```yml
custom:
serverless-offline-dynamodb-streams:
retries: 0 # disables retries
```
5 changes: 4 additions & 1 deletion packages/serverless-offline-dynamodb-streams/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class ServerlessOfflineDynamoDBStreams {
const dynamodbClient = this.getDynamoDBClient();
const dynamodbStreamsClient = this.getDynamoDBStreamsClient();
const tableName = this.getTableName(tableEvent);
const {retries = Infinity} = this.getConfig();

const streamARN = await fromCallback(cb =>
dynamodbClient.describeTable(
Expand Down Expand Up @@ -164,9 +165,11 @@ class ServerlessOfflineDynamoDBStreams {
new Writable({
objectMode: true,
write: (chunk, encoding, cb) => {
let attempts = 0;
const handleAttempt = () => {
if (retries < Infinity) attempts += 1;
this.eventHandler(streamARN, functionName, shardId, chunk, err =>
err ? handleAttempt() : cb()
err && attempts <= retries ? handleAttempt() : cb()
);
};

Expand Down