-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
56 lines (44 loc) · 1.62 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import {
AdminDisableUserCommand,
CognitoIdentityProviderClient
} from "@aws-sdk/client-cognito-identity-provider";
import {
SQSClient,
DeleteMessageCommand
} from "@aws-sdk/client-sqs";
const AWS_REGION = process.env.REGION;
const USERPOOL_ID = process.env.USERPOOL_ID;
const ENV = process.env.ENV;
const adminDisableUserCommandQueue = `https://sqs.us-west-1.amazonaws.com/213993515054/AdminDisableUserCommand-${ENV}`
/**
* @type {import('@types/aws-lambda').APIGatewayProxyHandler}
*/
export const handler = async (event) => {
const { body, receiptHandle } = event.Records[0];
const bodyObj = JSON.parse(body)
// disable unverified cognito user
try {
const input = {
UserPoolId: USERPOOL_ID,
Username: bodyObj.email
}
const adminDisableUserCommand = new AdminDisableUserCommand(input);
const cognitoClient = new CognitoIdentityProviderClient({ region: AWS_REGION });
await cognitoClient.send(adminDisableUserCommand);
} catch (error) {
console.error("disabling cognito user:", error.message)
}
// delete message from queue
try {
const deleteMessageInput = {
QueueUrl: adminDisableUserCommandQueue,
ReceiptHandle: receiptHandle
}
const deleteMessageCommand = new DeleteMessageCommand(deleteMessageInput)
const sqsClient = new SQSClient({ region: AWS_REGION })
await sqsClient.send(deleteMessageCommand)
} catch (error) {
console.error("deleting message from AdminDisableUserCommand queue:", error.message)
}
return { statusCode: 200 };
};