Skip to content

Instantly share code, notes, and snippets.

@carlosrymer
Created July 6, 2017 00:28
Show Gist options
  • Save carlosrymer/0d08a18f9e2b7c3b03013c454a4df7a5 to your computer and use it in GitHub Desktop.
Save carlosrymer/0d08a18f9e2b7c3b03013c454a4df7a5 to your computer and use it in GitHub Desktop.
A sample AWS Lambda function that retrieves rows from a Google Sheet.
'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