Serverless function is not hydrating response body in local API

I’m working on a list of events being pulled in through the google calendar API, through a lambda function in netlify. Running into a few issues, but i think they stem from this main problem.

At the heart of it my question is what is the correct way to hydrate this body response so that the call to the “api” can return a value. screen shot below.

I’ve written this a few ways, but don’t seem to get this working. It looks like the return statement fires before the eventList var has been updated with values from googles api.

I did have this working at one point locally throught netlify dev but in production would return an empty value - so i assumed there was a more correct way to make the call to google calendar api, and return the data in the function.

site: https://dfw-nets.netlify.app/
function: https://dfw-nets.netlify.app/.netlify/functions/getEvents

I’m not familiar with Google Calendar API, but the way I wait for response in my Functions is by wrapping them in a return statement. My first attempts were like yours, thinking I’d get the correct value, but I didn’t.

I currently have examples that involve FaunaDB, and it’s based on promises. I’m not sure if that’s the case with Calendar API.

Returning the Body Response in the callback solves the issue.