Search code examples
flutteraws-lambdaamazon-dynamodbamazon-cognitoaws-amplify

How to delete user data efficiently after he deletes his account in AWS


I have a mobile app written in Flutter using AWS Amplify. This app allows user to register/login on cognito and persist some information on dynamo db.

From what I've read in the aws documentation there isn't a built-in functionality in Amplify to delete the user from cognito with all his related data in one shot.

So this is what I was thinking to do (in order):

  • delete the user from Cognito
  • sign out the user with a proper message (ex. "your account has been deleted with success")
  • produce a "DELETE_ACCOUNT" event on a sqs queue consumed by a lambda that deletes the user entries from dynamo db.

The final step would be async so it wouldn't waste time to the user. I should deal with lambda timeout (which is of 15 minutes) in case the lambda weren't able to delete all the entries in time.

I would like to know if there was a better way to achieve my goal or if this solution is ok.


Solution

  • The solution you came up with is pretty much what you need to do. To my knowledge there are no special shortcuts so you have to implement the deletion logic yourself.

    Depending on how much data you have to delete you may have to deal with timeouts, but most importantly, make sure you have a way to deal with errors.

    The idea being that you want to make sure your lambda gets retried as many times as needed to ensure all data is deleted. This can be accomplished by making sure the DELETE_ACCOUNT message doesn't get removed from the queue until the query for data returns 0 results. And make sure your SQS queue is configured to re-deliver messages enough times.

    And configure a dead-letter queue to catch situations where the deletes are unsuccessful even after multiple tries.