I have a FastAPI method for delete_item in DynamoDb
@app.delete("/delete-student/{student_id}")
def delete_student(student_id : str):
db = connect_ddb()
try:
response = db.delete_item(Key={"id": student_id})
return response
except Exception as error:
return {"error message": error}
And I'm testing using the requests library
x = requests.delete('endpoint/prod/delete-student/7')
>>>
'{"error":"student_id: {student_id} does not exist"}'
I've successfully posted student id=7 and retrieved student id=7. So I'm confused what's wrong with the delete-student method. {"error message": ...} is not returned, but rather {"error":...} This means that the try clause worked and the response is from DynamoDb (not the except clause.)
So my question is, what issue does Ddb have with the argument, student_id?
Is Key={"id": student_id} wrong for delete_item? Note, this is the same argument for get_item, which does return the associated student.
You don't show your code that's returning the response. DynamoDB does not return the message you posted.
'{"error":"student_id: {student_id} does not exist"}
If the item didn't exist, DynamoDB would simply return a 200 success.
The parameters expected by a deleteItem are exactly the same as a getItem which is the full primary key.