Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. const AWS = require("aws-sdk");
  2. const crypto = require("crypto");
  3.  
  4. const Cognito = new AWS.CognitoIdentityServiceProvider();
  5.  
  6. exports.handler = async (event) => {
  7. const clientId = process.env.COGNITO_CLIENT_ID;
  8. const clientSecret = process.env.COGNITO_CLIENT_SECRET;
  9. const {username, password, email} = event;
  10.  
  11. const secretHash = crypto.createHmac("SHA256", clientSecret).update(email + clientId).digest("base64");
  12.  
  13. const params = {
  14. ClientId: clientId,
  15. SecretHash: secretHash,
  16. Password: password,
  17. Username: username,
  18. UserAttributes: [
  19. {
  20. Name: "email",
  21. Value: email
  22. }
  23. ]
  24. };
  25.  
  26. try {
  27. const authRes = await Cognito.signUp(params).promise();
  28. return {
  29. data: authRes
  30. }
  31. } catch(err) {
  32. console.log("Error: ", err);
  33. return {
  34. err
  35. }
  36. }
  37. };
  38.  
  39. {
  40. "Version": "2012-10-17",
  41. "Statement": [
  42. {
  43. "Effect": "Allow",
  44. "Action": "logs:CreateLogGroup",
  45. "Resource": "arn:aws:logs:us-east-1:<account_id>:*"
  46. },
  47. {
  48. "Effect": "Allow",
  49. "Action": [
  50. "logs:CreateLogStream",
  51. "logs:PutLogEvents"
  52. ],
  53. "Resource": [
  54. "arn:aws:logs:us-east-1:<account_id>:log-group:/aws/lambda/create_user:*"
  55. ]
  56. }
  57. ]
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement