Skip to content

[BUG] The "create" function under aws-python-http-api-with-pynamodb is not idempotent #659

@Nsupyq

Description

@Nsupyq

The function create under aws-python-http-api-with-pynamodb example is not idempotent and may create multiple extra todos.

a_todo = TodoModel(todo_id=str(uuid.uuid1()),
                   text=data['text'],
                   checked=False)

a_todo.save()

The todo_id is randomly generated. Thus, when the function fails after the new todo is saved, the function will be retried and create a new todo again with a different todo_id. Similar issue exists in aws-python-rest-api-with-dynamodb/todos.

This can be fixed by making the function idempotent. We can use the awsRequestId to be todo_id. This is a unique identifier provided by AWS Lambda and is the same in retries. Then the function will create only one new todo. Another way to fix it is requiring the client to provide a parameter to be todo_id. The client can generate such an identifier via uuid API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions