Delete an Item in a DynamoDB Table

To delete an item, you'll specify the primary key of the item you wish to remove. This operation deletes the item from the table and frees up space. Here are the steps in Node.js and Python:

Node.js:

const params = {  
    TableName: table,  
    Key: {  
       'UserID': userID  
    }  
};  
      
docClient.delete(params, function(err, data) {  
    if (err) console.error('Error', err);  
    else  console.log('DeleteItem succeeded:', data);  
});

This Node.js snippet specifies parameters to delete an item identified by 'UserID' from 'UserTable', and executes the deletion, logging the result.

Python:

response = table.delete_item(  
    Key={  
       'UserID': 'user_001'  
    }  
)  
print("DeleteItem succeeded:", response)

The Python code snippet deletes an item from 'UserTable' using the specified 'UserID' with Boto3's delete_item method, and prints the success response.