Skip to content

Instantly share code, notes, and snippets.

@AndrewBestbier
Created October 21, 2019 15:55
Show Gist options
  • Select an option

  • Save AndrewBestbier/458868f883a1170fbf02e74791a40b3c to your computer and use it in GitHub Desktop.

Select an option

Save AndrewBestbier/458868f883a1170fbf02e74791a40b3c 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 params = {
TableName: "books" // The name of your DynamoDB table
};
try {
// Utilising the scan method to get all items in the table
const data = await documentClient.scan(params).promise();
const response = {
statusCode: 200,
body: JSON.stringify(data.Items)
};
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