Lang
Blog

AWS Cognito User Data Replication Across Regions: Step-by-Step Guide

ByAkshay Mewara
June 19th . 6 min read
import boto3
 
def lambda_handler(event, context):
    dynamodb = boto3.resource('dynamodb')
    table = dynamodb.Table('UserTable')
    
    user_data = {
        'email': event['request']['userAttributes']['email'],
        'sub': event['userName']
    }
    
    table.put_item(Item=user_data)
    
    return event
import boto3
 
def lambda_handler(event, context):
    cognito = boto3.client('cognito-idp')
    user_pool_id = 'your_user_pool_id'
    
    for record in event['Records']:
        if record['eventName'] == 'INSERT':
            new_image = record['dynamodb']['NewImage']
            email = new_image['email']['S']
            sub = new_image['sub']['S']
            
            cognito.admin_create_user(
                UserPoolId=user_pool_id,
                Username=sub,
                UserAttributes=[
                    {'Name': 'email', 'Value': email},
                    {'Name': 'email_verified', 'Value': 'true'}
                ]
            )
            
    return 'User created'
Share:
0
+0