in src/books/create/index.ts [22:58]
async function handler(event: any): Promise<APIGatewayProxyResult> {
let response: APIGatewayProxyResult;
try {
const client = new AWS.DynamoDB(ddbOptions);
const book = JSON.parse(event.body);
const { isbn, title, year, author, publisher, rating, pages } = book;
const params: AWS.DynamoDB.Types.PutItemInput = {
TableName: process.env.TABLE || 'books',
Item: {
isbn: { S: isbn },
title: { S: title },
year: { N: year.toString() },
author: { S: author },
publisher: { S: publisher },
rating: { N: rating.toString() },
pages: { N: pages.toString() }
}
};
await client.putItem(params).promise();
response = {
statusCode: 201,
headers: { 'Content-Type': 'application/json' },
body: ''
};
} catch (e) {
response = {
statusCode: 500,
headers: {},
body: ''
};
}
return response;
}