Last active
June 14, 2024 13:10
-
-
Save proton0210/a1755e9864ccca3a07d5dd2b0d833c2c to your computer and use it in GitHub Desktop.
4-sf-PostConfirmation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// npm i @aws-sdk/client-dynamodb @aws-sdk/util-dynamodb | |
// npm i -D @types/aws-lambda esbuild | |
import { DynamoDBClient, PutItemCommand } from "@aws-sdk/client-dynamodb"; | |
import { PostConfirmationConfirmSignUpTriggerEvent } from "aws-lambda"; | |
import { marshall } from "@aws-sdk/util-dynamodb"; | |
const client = new DynamoDBClient(); | |
exports.handler = async function ( | |
event: PostConfirmationConfirmSignUpTriggerEvent | |
): Promise<PostConfirmationConfirmSignUpTriggerEvent> { | |
const tableName = process.env.TABLE_NAME; | |
console.log(event, "event"); | |
const date = new Date(); | |
const isoDate = date.toISOString(); | |
const params = { | |
TableName: tableName, | |
Item: marshall({ | |
UserID: event.request.userAttributes.sub, | |
Email: event.request.userAttributes.email, | |
Name: event.request.userAttributes.name, | |
CreateAt: isoDate, | |
__typename: "User", | |
}), | |
}; | |
try { | |
await client.send(new PutItemCommand(params)); | |
} catch (error: any) { | |
console.log(error); | |
} | |
return event; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment