Untitled

mail@pastecode.io avatar
unknown
plain_text
24 days ago
963 B
3
Indexable
Never
import json
import boto3

# Initialize DynamoDB client
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('user_info')  # Replace with your DynamoDB table name

def lambda_handler(event, context):
    # Parse data from the request body
    body = json.loads(event['body'])
    name = body['name']
    email = body['email_address']
    password = body['password']

    # DynamoDB put item
    try:
        response = table.put_item(
            Item={
                'email_address': email_address,
                'name': name,
                'password': password
            }
        )
        print("PutItem succeeded:", response)
        return {
            'statusCode': 200,
            'body': json.dumps('User information saved successfully')
        }
    except Exception as e:
        print("Error putting item:", e)
        return {
            'statusCode': 500,
            'body': json.dumps('Error saving user information')
        }
Leave a Comment