Hi all, I’ve recently been trying to set up a Lambda Function on my site. The rest of the site is running on Gatsby. I’m able to get some basic functions working in development and production (e.g. returning a “hello world”), but I’m running into a problem whenever I try something more complex.
My function always seems to return an error in development which says Function invocation failed: TypeError: Expected signal to be an instanceof AbortSignal
. I haven’t tried getting it to work in production (although it obviously won’t work as it stands, relying on .env).
For instance, here is the code I’m trying to get to work, lifted from this gist.
require("dotenv").config({ debug: process.env.DEBUG })
const Airtable = require("airtable")
Airtable.configure({
endpointUrl: "https://api.airtable.com",
apiKey: process.env.AIRTABLE_PASS,
})
var base = Airtable.base(process.env.AIRTABLE_ID)
exports.handler = function(event, context, callback) {
const allRecords = []
base('Main')
.select({
maxRecords: 100,
view: 'all'
})
.eachPage(
function page(records, fetchNextPage) {
records.forEach(function(record) {
allRecords.push(record)
})
fetchNextPage()
},
function done(err) {
if (err) {
callback(err)
} else {
const body = JSON.stringify({ records: allRecords })
const response = {
statusCode: 200,
body: body,
headers: {
'content-type': 'application/json',
'cache-control': 'Cache-Control: max-age=300, public'
}
}
callback(null, response)
}
}
)
}
The error occurs whether I hit the url from my browser, or send a GET or POST request through Postman or a form.
The site name is affectionate-engelbart-b6885d
.
Happy to post error logs if that’s helpful. Thank you!