lambda处理程序回复后如何等待goroutine完成

I'm writing a slack bot with Go and Aws Lambda. Slack requires for the bot to reply within 3 seconds. However, sometimes I can't make it reply that fast, cuz it's "talking" to other serverless applications for requesting some data or dispatching tasks. I have never worked with goroutines before, but I was hoping that I could implement something like this:

  1. Lambda receives a request
  2. The bot creates a goroutine that will process this request and act accordingly on it
  3. The handler doesn't wait for all these actions to complete but replies right away with 200.
  4. Lambda continues to run until goroutine is finished.

I'm not sure if that's even possible.

I've read about sync.WaitGroup, but I'm not sure how to incorporate it together with main function. Should I use it inside the handler? But I need to return response and that's not a function that I can wrap into a goroutine.

Ideally, I would like for handler to reply right away and then process goroutine in the background.

Don't try to do anything in your lambda handler after the request finishes.

A more reliable approach:

  1. Accept the call and record whatever input data is needed.
  2. Put the data in SQS
  3. Respond with HTTP 200
  4. Another (SQS triggered) function does the processing and if needed, calls Slack back on recorded response_url