Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Triggering a Lambda function upon deleting a user on AWS Cognito User Pool

AWS Cognito User Pools have some pre-defined events to handle user signup, confirmation etc. The full list is here.

However, there is no apparent trigger for deleting a user.

So, is there any way one can trigger a Lambda function when a user is deleted from Cognito User Pool (of course, with arguments like username and/or email address)?

like image 689
vahdet Avatar asked Jun 15 '18 13:06

vahdet


People also ask

What events can trigger an AWS Lambda function?

You can trigger a Lambda function on DynamoDB table updates by subscribing your Lambda function to the DynamoDB Stream associated with the table. You can associate a DynamoDB Stream with a Lambda function using the Amazon DynamoDB console, the AWS Lambda console, or Lambda's registerEventSource API.

How AWS Lambda gets triggered?

A trigger is a Lambda resource or a resource in another service that you configure to invoke your function in response to lifecycle events, external requests, or on a schedule. Your function can have multiple triggers. Each trigger acts as a client invoking your function independently.


1 Answers

If you are using "Amazon Cognito Sync":

Amazon Cognito raises the Sync Trigger event when a dataset is synchronized. You can use the Sync Trigger event to take an action when a user is updated or deleted. Please have a look on below official document for more information and steps.

Ref: https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-events.html

Records updated by the app user will have the 'op' field set as “replace” and the records deleted will have 'op' field as "remove".

According to above point in referenced documentation op field can help you to identify operation, So if value is "removed" in op then you can perform your actions for your business logic requirement.

If you are not using "Amazon Cognito Sync":

  1. Create user records in DynamoDB table "user" using Post Confirmation Lambda Trigger.
  2. Build your own user listing based on DynamoDB table "user".
  3. Build your own user delete api using lambda function and aws api gateway.
  4. You lambda function should handle delete user from cognito & also your business logic that you want to perform.
like image 162
Rajesh Meniya Avatar answered Sep 20 '22 16:09

Rajesh Meniya