diff --git a/packages/serverless-offline-dynamodb-streams/README.md b/packages/serverless-offline-dynamodb-streams/README.md index fc5f0e76..7407f3a3 100644 --- a/packages/serverless-offline-dynamodb-streams/README.md +++ b/packages/serverless-offline-dynamodb-streams/README.md @@ -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 +``` diff --git a/packages/serverless-offline-dynamodb-streams/src/index.js b/packages/serverless-offline-dynamodb-streams/src/index.js index 4193db11..7209b8da 100644 --- a/packages/serverless-offline-dynamodb-streams/src/index.js +++ b/packages/serverless-offline-dynamodb-streams/src/index.js @@ -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( @@ -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() ); };