import crypto from "crypto" ; import { DynamoDBClient , PutItemCommand } from "@aws-sdk/client-dynamodb" ; import { marshall } from "@aws-sdk/util-dynamodb" ; import { success , failure } from "./libs/response" ; import { APIGatewayEvent } from "aws-lambda" ; export const handler = async ( event ) => { const data = JSON . parse ( event . body || "{}" ) ; const params = { TableName : process . env . NOTES_TABLE_NAME || "" , Item : marshall ( { noteId : crypto . randomBytes ( 20 ) . toString ( "hex" ) , content : data . content , createdAt : Date . now ( ) . toString ( ) , ... ( data . attachment && { attachment : data . attachment } ) , } ) , } ; try { const client = new DynamoDBClient ( { } ) ; await client . send ( new PutItemCommand ( params ) ) ; return success ( params . Item ) ; } catch ( e ) { console . log ( e ) ; return failure ( { status : false } ) ; } } ;