UNPKG

serverless-sam

Version:

Serverless framework plugin to export AWS SAM templates for a service

32 lines (27 loc) 786 B
'use strict'; const AWS = require('aws-sdk'); // eslint-disable-line import/no-extraneous-dependencies const dynamoDb = new AWS.DynamoDB.DocumentClient(); const params = { TableName: process.env.DYNAMODB_TABLE, }; module.exports.list = (event, context, callback) => { // fetch all todos from the database dynamoDb.scan(params, (error, result) => { // handle potential errors if (error) { console.error(error); callback(null, { statusCode: error.statusCode || 501, headers: { 'Content-Type': 'text/plain' }, body: 'Couldn\'t fetch the todos.', }); return; } // create a response const response = { statusCode: 200, body: JSON.stringify(result.Items), }; callback(null, response); }); };