Skip to content

Instantly share code, notes, and snippets.

@jig
Last active September 18, 2024 06:23
Show Gist options
  • Save jig/1c9514a8104fa28012a7170aa5023c19 to your computer and use it in GitHub Desktop.
Save jig/1c9514a8104fa28012a7170aa5023c19 to your computer and use it in GitHub Desktop.
Delete several items at once on AWS DynamoDB using AWS CLI

You can can use:

aws dynamodb batch-write-item --request-items file:///tmp/deletes.json

where the file /tmp/deletes.json must have this structure like this:

{
    "MY_TABLE": [
        {
            "DeleteRequest": {
                "Key": {
                    "partition-key-name": {
                        "S": "value to delete"
                    },
                    "sort-key-name": {
                        "S": "value to delete"
                    }
                }
            }
        },
               {
            "DeleteRequest": {
                "Key": {
                    "partition-key-name": {
                        "S": "another value to delete"
                    },
                    "sort-key-name": {
                        "S": "another value to delete"
                    }
                }
            }
        },
        ...
    ]
}

You can remove several items with a single batch.

@shapan1
Copy link

shapan1 commented Nov 24, 2021

For my specific scenario, I ahve a table with PK and SK as accountId and profileId. there are multiple accountIds and multiple profileIds under each accountID. I want to delete all items with a specific PK e.g. PK = "1234".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment