Search code examples
pythonaws-lambdaslackslack-api

Slack Slash commands error: failed with the error "operation_timeout"


I am using Slack Slash commands to send requests to my AWS Lambda python app.

However, after sending the command, Slack is returning the message failed with the error "operation_timeout":

operation_timeout

Even though I received this message, my request is sent successfully, and the job is done.

I just want to know how to get rid of this message sent by slack.

I know that Slack expects an HTTP POST 200 OK as acknowledgement response as from this link here but I did send one the moment the payload is received as shown here:

lambda_handler.py

def slack_acknowledgment_response(resonse_url):

    # Make API Call to Slack API
    requests.post(
        resonse_url, 
        {'text': 'Test'}
    )


# This is my main event
def main(event, context):

    payload = parse_qs(event['postBody'])

    response_url = payload['response_url'][0]

    slack_acknowledgment_response(response_url)

    time.sleep(5)

I intentionally added a sleep period of 5 seconds because I get this error if the runtime of my script takes longer than 3 seconds, even though I already sent an acknowledgement before 3 seconds.

Can someone please help out ?


Solution

  • As you said in your link, slack says the 200 response message must be received within 3000ms (3 seconds). However, I think you're misinterpreting the expectation. It want's the 200 response to the request Slack sent to you. You can send the POST to the response_url within 30 seconds, but it still needs to initial response within 3 seconds.

    If you're expecting the process to take more than 3 seconds, you should probably figure out a way to do asynchronous processing. For example, queuing the jobs you received in Lambda to an SQS queue, then using the notification's response_url to send a response (as long as you can process it within 30 seconds).

    You may want to look at the answers to this question to see ways you can have your Lambda function return a response immediately, then do asynchronous processing via a second Lambda function.