Help

The Community will be temporarily unavailable starting on Friday February 28. We’ll be back as soon as we can! To learn more, check out our Announcements blog post.

Calling AirTable API from inside a Lambda function

Topic Labels: ImportingExporting
1514 1
cancel
Showing results for 
Search instead for 
Did you mean: 
AHA_Team
4 - Data Explorer
4 - Data Explorer

Hi,

I am trying to call AirTable from inside a Lambda function using a local instance (using AWS SAM).
If I just use node/js as is, it all works fine (so I know the code should work). But once I put it inside the Lambda and try to run it, I see nothing in the console.
Any clues as to what is going on?
This is the code I am running


let response;
exports.lambdaHandler = async (event, context) => {
    var Airtable = require('airtable');
    var base = new Airtable({apiKey: 'k***************3'}).base('ap****************8jC');

    base('Course Locations').select({
        maxRecords: 3,
        view: "Myview"
    }).eachPage(function page(records, fetchNextPage) {
        records.forEach(function(record) {
            console.log('Retrieved');//, record.get('Name (Abbrev.)')
        });

    }, function done(err) {
        if (err) {
            console.error(err);
            return;
        }
    });



    try {
        response = {
            'statusCode': 200,
            'body': JSON.stringify({
                message: 'hello world',
            })
        }
    } catch (err) {
        console.log(err);
        return err;
    }
    return response
};

I do see the “hello world” in the log/response.
The code as is runs well when I use it in a simple javascript file and run it with node.
In simple node, I do see the console.log('Retrieved'); but not inside a lmbda

1 Reply 1
Stephanie_Hekke
4 - Data Explorer
4 - Data Explorer

I ran into a very similar problem and the code in this tutorial fixed it for me: Airtable API Tutorial with cURL and JavaScript ― Scotch.io

Originally, I was using the code from the airtable API and it only worked locally. This works locally and in my aws console.