502 internal server error response from API gateway from lambda function

百般思念 提交于 2020-01-05 07:18:13

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/55051452/502-internal-server-error-response-from-api-gateway-from-lambda-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!