1

I am trying to deploy a simple Slack lambda api which uses the @slack/client library to remove members and pinned messages from a specific channel. The issue that I am running into is the function executes without a problem, and it is removing the channel members without a problem, but my Lambda function keeps returning:

HTTP/1.1 502 Bad Gateway
...
X-Cache: Error from cloudfront
...

{
    "message": "Internal server error"
}

as the response body. When I check the logs using sls logs -f api, I dont see any errors there either. I see the console.log of my function successfully executing.

My serverless.yml is as follows:

provider:
  name: aws
  runtime: nodejs10.x
  profile: serverless

functions:
  api:
    handler: handler.api
    timeout: 30
    events:
      - http:
          method: POST
          path: clean

And my api code, i have removed the unnecessary function codes as they are doing their work, is :

module.exports.api = async (event, context, callback) => {
  let channel = JSON.parse(event.body).ctf
  let id = await findChannelId(channel)
  removeMembersFromChannel(id[0]).then(() => {
    removePinsFromChannel(id[0]).then(() => {
      callback(null, {
        statusCode: 200,
        body: JSON.stringify({
          message: `Cleaned ${channel} ${id}`,
        }, null, 2),
      })
    })
  })
};

Things I have tried:

  • returning the response instead of using the callback
  • using promises and async await
  • testing the function locally using sls invoke local
  • most of my search shows that this could be a permission issue, but all the references are for s3 usage which is something i am not using.

Questions

  • Why am I getting this error, and how I can resolve this?
  • After referenceing this In the handler function, I am using JSON.stringify. Using the serverless-framework, how can i avoid using Lambda proxy integration?
Community
  • 1
  • 1
securisec
  • 3,435
  • 6
  • 36
  • 63

1 Answers1

1

Please, add console.log for detailed logging via cloudwatch and use x-ray. Some typical problems with cloudfront: - a lot of time to propagate to edge locations (maybe u need recreate your cdn) - logs from lambda@edge locates in invoked region

Ivan Shumov
  • 626
  • 3
  • 6