Skip to content

Instantly share code, notes, and snippets.

@AndrewBestbier
Created October 21, 2019 16:40
Show Gist options
  • Select an option

  • Save AndrewBestbier/6a3e234499c2d2d5eb2d6de596e887c6 to your computer and use it in GitHub Desktop.

Select an option

Save AndrewBestbier/6a3e234499c2d2d5eb2d6de596e887c6 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; // Extracting an id from the request path
const params = {
TableName: "books", // The name of your DynamoDB table
Key: { id } // They key of the item you wish to find.
};
try {
// Utilising the get method to retrieve an indvidual item
const data = await documentClient.get(params).promise();
const response = {
statusCode: 200,
body: JSON.stringify(data.Item)
};
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