Skip to content

Instantly share code, notes, and snippets.

@AndrewBestbier
Last active February 18, 2020 10:08
Show Gist options
  • Select an option

  • Save AndrewBestbier/38655a9dc954d0089f8a86553f16fb9e to your computer and use it in GitHub Desktop.

Select an option

Save AndrewBestbier/38655a9dc954d0089f8a86553f16fb9e to your computer and use it in GitHub Desktop.
const AWS = require("aws-sdk");
const documentClient = new AWS.DynamoDB.DocumentClient();
exports.handler = async event => {
const {
pathParameters: { id }
} = event;
const { title } = JSON.parse(event.body);
const params = {
TableName: "books",
Item: {
id: id,
title: title
}
};
try {
const data = await documentClient.put(params).promise();
const response = {
statusCode: 200
};
return response;
} catch (e) {
return {
statusCode: 500
};
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment