1

this is my lambda function: I've obviously blanked out the config for now

exports.handler = (event, context) => {
    var config = {

    };
    firebase.initializeApp(config)

    const gymData = firebase.database().ref("gymData/exercises")
    axios.get('https://------/gymData/exercises.json').then(({data}) => {
      const returnedData = Object.values(data)
      const response = {
        statusCode: '200',
        body: JSON.stringify(returnedData),
        headers: {
          'Content-Type': 'application/json',
        }
      }
      context.succeed(response)
    })
};

when I test my lambda it's getting the json back in the correct form, this is just a snippet of that data

{
  "statusCode": "200",
  "body": "[{\"bodyPart\":\"arms\",\"cardio\":false,\

however, whenever I invoke API gateway to trigger the lambda and test it, I get a 502. on the API page it just says

{
  "message": "Internal server error"
}

Any reason why I'm getting this?

I've done some googling and most answers say you have to return a statusCode. Clearly I am doing that and it's still broken

any ideas?

perhaps im invoking api gateway wrong?

Red Baron
  • 7,181
  • 10
  • 39
  • 86

1 Answers1

0

Figured it out. I hadn't set permissions for it facepalm. I was using the ANY request. but once I did a get request it worked.

Red Baron
  • 7,181
  • 10
  • 39
  • 86