Untitled

mail@pastecode.io avatar
unknown
plain_text
21 days ago
1.1 kB
1
Indexable
Never
// Lambda function to store user information in DynamoDB

const AWS = require('aws-sdk');
const dynamodb = new AWS.DynamoDB.DocumentClient();

exports.handler = async (event) => {
    // Parse data from the request body
    const { name, email, password } = JSON.parse(event.body);

    // DynamoDB parameters
    const params = {
        TableName: 'user_info', // Replace with your DynamoDB table name
        Item: {
            email: email,
            name: name,
            password: password
        }
    };

    try {
        // Put item in DynamoDB table
        await dynamodb.put(params).promise();
        
        // Return success response
        return {
            statusCode: 200,
            body: JSON.stringify({ message: 'User information saved successfully' })
        };
    } catch (error) {
        // Return error response
        console.error('Error saving data: ', error);
        return {
            statusCode: 500,
            body: JSON.stringify({ message: 'Error saving user information' })
        };
    }
};
Leave a Comment