You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the function fails after executing dynamoDb.put(params).promise() because runtime error or other reasons, AWS Lambda will retry the function. Then uuidv4() will return another different id and dynamoDb.put(params).promise() will be executed again, which creates another new record in database.
This can be fixed by making the function idempotent. First, the primary key should be provided by users as a parameter. This can avoid generating a different new primary key on retry. Second, before executing dynamoDb.put(params).promise(), the function should check whether the record with the same primary key have been in the database. If so, that means the current execution is a retry and the function should not write the database again.
Please let me know if I've missed something or if my understanding of the code is incorrect. Thanks!
The text was updated successfully, but these errors were encountered:
Sorry, I think it is unnecessary to check whether the record with the same primary key have been in the database. We just need to ensure there will be only one new record in database. I have modified my PR #8 and removed unnecessary check.
The function in index.js is not idempotent and may insert multiple duplicate records into database.
When the function fails after executing
dynamoDb.put(params).promise()
because runtime error or other reasons, AWS Lambda will retry the function. Thenuuidv4()
will return another different id anddynamoDb.put(params).promise()
will be executed again, which creates another new record in database.This can be fixed by making the function idempotent. First, the primary key should be provided by users as a parameter. This can avoid generating a different new primary key on retry. Second, before executing
dynamoDb.put(params).promise()
, the function should check whether the record with the same primary key have been in the database. If so, that means the current execution is a retry and the function should not write the database again.Please let me know if I've missed something or if my understanding of the code is incorrect. Thanks!
The text was updated successfully, but these errors were encountered: