Help

Re: How to pass event parameters to AWS Lambda function in Automation Script?

3486 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Yongjoon_Kim
5 - Automation Enthusiast
5 - Automation Enthusiast

I have an AWS Lambda function written in python that is initiated by a Zapier trigger that I set up. As I pass some input parameters to the function in the Zapier trigger, I can access to the input parameters in my python code by using variables such as event[parameter1] . It perfectly works.

I’m trying to access the same Lambda function in Airtable Scripting environment. In order to do it, I set up an API Gateway trigger for the Lambda function, but I can’t figure out how to pass input parameters in the vanilla JS environment. Below is the code that I have, which gives me “Internal Server Error” .

Your help would be definitely appreciated!

    const awsUrl = "https://random-id.execute-api.us-west-2.amazonaws.com/default/lambda-function";
    let event = {
        "queryStringParameters": {
            "folder_id": consFolderId,
            "email": email
        }
    };

    let response = await fetch(awsUrl, {
        method: "POST",
        body: JSON.stringify(event),
        headers: {
            "Content-Type": "application/json",
        }
    });
    console.log(await response.json());
3 Replies 3

Hi @Yongjoon_Kim, and welcome to the community!

That doesn’t seem to be your problem. The event payload seems properly configured.

Unfortunately, Zapier is concealing many of the API details. In the future, I would recommend you hop over to Autocode which is like Heroku + Zapier and would allow you to prototype your API with a little more transparency and certainly ease of testing.

I would try this change, but note that depending on your Lamda service configuration, this may not be the entire resolution to your issue. But given the reference to await response.json() you are expecting the response to be parseable JSON data so I would add the Accept directive while also setting Content-Type to lower case (it matters).

let response = await fetch(awsUrl, {
    method: "POST",
    body: JSON.stringify(event),
    headers: {
        "Accept": "application/json",
        "content-type": "application/json",
    }
});

You may also want to experiment by managing the call into Lambda as a Promise(). Something like…

async function callMyPythonService(postURL, postOptions) {
    await fetch(postURL, postOptions)
        .then((resp) => resp.json())
        .then(function(data) {
            return data;
        })
        .catch(function(e) {
            output.markdown(e.message);
        });
}
Yongjoon_Kim
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi @Bill.French,

Thank you so much for your comments! Actually, your first suggestion was really helpful. I was able to solve this problem by

  1. Including the “Accept” header that you mentioned
  2. Setting up proper query string parameters in ‘Method Request’ and ‘Integration Request’ in my API Gateway that is connected to my Lambda function

Due to the structural difference between the payload in Zapier’s Lambda trigger and the payload from the API Gateway, I had to duplicate my existing Lambda function with a small tweak about receiving the input event, but that was it.

I’m super happy to solve this issue with your advice! It really made my day! Hope I can contribute to this community in the future.

You’re welcome! Now go break something else so we can all learn some more. :winking_face: