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?
1
  • I encountered a similar issue. Turns out my path to the handler had a typo. Commented Dec 31, 2020 at 17:58

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.