Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const AWS = require("aws-sdk");
- const crypto = require("crypto");
- const Cognito = new AWS.CognitoIdentityServiceProvider();
- exports.handler = async (event) => {
- const clientId = process.env.COGNITO_CLIENT_ID;
- const clientSecret = process.env.COGNITO_CLIENT_SECRET;
- const {username, password, email} = event;
- const secretHash = crypto.createHmac("SHA256", clientSecret).update(email + clientId).digest("base64");
- const params = {
- ClientId: clientId,
- SecretHash: secretHash,
- Password: password,
- Username: username,
- UserAttributes: [
- {
- Name: "email",
- Value: email
- }
- ]
- };
- try {
- const authRes = await Cognito.signUp(params).promise();
- return {
- data: authRes
- }
- } catch(err) {
- console.log("Error: ", err);
- return {
- err
- }
- }
- };
- {
- "Version": "2012-10-17",
- "Statement": [
- {
- "Effect": "Allow",
- "Action": "logs:CreateLogGroup",
- "Resource": "arn:aws:logs:us-east-1:<account_id>:*"
- },
- {
- "Effect": "Allow",
- "Action": [
- "logs:CreateLogStream",
- "logs:PutLogEvents"
- ],
- "Resource": [
- "arn:aws:logs:us-east-1:<account_id>:log-group:/aws/lambda/create_user:*"
- ]
- }
- ]
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement