Cognito user from lambda


HackerNoon.com
Published in

HackerNoon.com

Nick Saponaro

Jun 12, 2019

4 min read

How To Add New Cognito Users to DynamoDB Using Lambda

That’s a lot of servers

Motivation

Pre-requisites

Initial set up

Create an IAM Role for your Lambda Function

Create a new Lambda Function

Write your function

Cognito to DynamoDB

What exactly is going on in this Gist?

Set up environment variables

const tableName = process.env.TABLE_NAME;    
const region = process.env.REGION;
const defaultAvi = 'https://YOUR/DEFAULT/IMAGE';
aws.config.update({region: region});

Modify the database parameters to your liking

// -- Write data to DDB        
let ddbParams = {
Item: {
'id': {S: event.request.userAttributes.sub},
'__typename': {S: 'User'},
'picture': {S: defaultAvi},
'username': {S: event.userName},
'name': {S: event.request.userAttributes.name},
'skillLevel': {N: '0'},
'email': {S: event.request.userAttributes.email},
'createdAt': {S: date.toISOString()},
},
TableName: tableName
};

Test the function

Test user request

Create a post-confirmation trigger in Cognito

That’s it

Elijah McClain, George Floyd, Eric Garner, Breonna Taylor, Ahmaud Arbery, Michael Brown, Oscar Grant, Atatiana Jefferson, Tamir Rice, Bettie Jones, Botham Jean

Comments

Popular posts from this blog

A re-introduction to JavaScript (JS tutorial)

Using a GraphQL API in React

GraphQL Query Options