Created
July 6, 2017 00:28
-
-
Save carlosrymer/0d08a18f9e2b7c3b03013c454a4df7a5 to your computer and use it in GitHub Desktop.
A sample AWS Lambda function that retrieves rows from a Google Sheet.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const GoogleSpreadsheet = require('google-spreadsheet'); | |
const spreadsheet = new GoogleSpreadsheet('1tVc-GnBIAAWbdCX7Zn9n-9V8j_rnv7meU22EubLN6G0'); // Sheet ID (visible in URL) | |
exports.handler = (event, context, callback) => { | |
return spreadsheet.getInfo((sheetError, info) => { | |
if (sheetError) { | |
console.error(sheetError); | |
return callback(sheetError); | |
} | |
const sheet = info.worksheets[0]; | |
const rowOptions = { | |
limit : 100000, | |
offset : 0 | |
} | |
return sheet.getRows(rowOptions, (rowsError, rows) => { | |
if (rowsError) { | |
console.error(rowsError); | |
return callback(rowsError); | |
} | |
return callback(null, rows); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment