I’m doing something in a kind of naive way. I thin...
# help
I’m doing something in a kind of naive way. I think perhaps what I “should” do is different. Would love to hear how you might handle this. I send an SMS form my app. I store the message:
Copy code
pk: SID#${messageid} | sk: SID#${messageid} | messageStatus | gsipk
Then twilio hits a callback with the SID# where I update the status. The front end polls against the gsipk Once the
is delivered or
you can resend. This works pretty great 🎉. But I’m now storing each message in the database. Which is not needed. So, after creating a message, I’m just deleting the old message.
Copy code
await dynamoDb.put(params);

    if (shouldDeleteOldMessage) {
      const existingItem = {
        TableName: process.env.TABLE_NAME,
        Key: {
          pk: existingPk,
          sk: existingPk,
      await dynamoDb.delete(existingItem);
Seems bad to make the front end wait until after I delete the item (or worse fail because that operation fails. I have some alternative thoughts but I’m curious what you’d do?
The simplest thing is to have a cron cleanup on schedule
Or you'd have to have the frontend poll twilio (through your API) to avoid storing anything
Another option is to make the PK something that's consistent, like the user id or something so you don't need to seperately delete
Then I have an issue with the reply from the twilio webhook, since I don’t have the userId. but I def tried that path!
You can set a TTL to auto delete items after a set time, but that'll only be simpler if you want to delete all messages
You could have a TTL set only for those messages you wanted to delete