slackapi / python-slack-events-api

Slack Events API adapter for Python (Flask required)
https://api.slack.com/events
MIT License
343 stars 116 forks source link

Is this compatible with AWS Lambda? #36

Closed vadmchris closed 4 years ago

vadmchris commented 6 years ago

Deploy with Zappa to AWS Lambda

Describe your issue here.

What type of issue is this? (place an x in one of the [ ])

Requirements

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackeventsapi version: SlackEventAdapter python version: 3.6 OS version(s): Linux (Virtual Env inside Docker container)

Expected result:

I want it to run as a regular Flask app or be able to specify an AWS gateway URL

Actual result:

Running on http://127.0.0.1:5000/

It treats my AWS environment as local host.

Attachments:

Error message after trying to deploy to Lambda:

Error: Warning! Status check on the deployed lambda failed. A GET request to '/' yielded a 504 response code.

[1537802873064] [INFO] 2018-09-24T15:27:53.27Z 6395b256-c00e-11e8-8c99-f1ee495556a5 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) [1537802898072] 2018-09-24T15:28:18.071Z 6395b256-c00e-11e8-8c99-f1ee495556a5 Task timed out after 30.03 seconds

datashaman commented 6 years ago

Try running your flask on 0.0.0.0:

flask run -h 0.0.0.0
aoberoi commented 5 years ago

@vadmchris did the advice above help?

i'd like to avoid building platform-specific implementations (like AWS Lambda) into this package, but maybe we can produce an FAQ about what it takes to get this package running on certain environments. We just learned about some issues on Google App Engine in #43.

it sounds like you need to create a handler for a GET request to the root path (AWS Lambda uses this as a status check to see if the server is up). we don't supply one for you, but you can add one pretty easily. it would look something like this.

from flask import Flask
from slackeventsapi import SlackEventAdapter

# This `app` represents your existing Flask app
app = Flask(__name__)

# This route should respond to the status request
@app.route("/")
def status():
  return "OK"

# Bind the Events API route to your existing Flask app by passing the server
# instance as the last param, or with `server=app`.
slack_events_adapter = SlackEventAdapter(SLACK_SIGNING_SECRET, "/slack/events", app)

# Example
@slack_events_adapter.on("reaction_added")
def reaction_added(event):
  emoji = event.get("reaction")
  print(emoji)

# Start the server on port 3000
if __name__ == "__main__":
  app.run(port=3000)
devblueray commented 5 years ago

You should be able to use this on lambda without much issue. You set it up like you would any other production flask app with wsgi then point the handler to the wsgi. Zappa and Serverless framework takes care of this for you. I'll try to remember to add an example a bit later but look at the serverless-wsgi plugin, it's fairly self explanatory. I will be setting an app up on lambda using this tomorrow so I'll update then.

stevengill commented 4 years ago

I'm going to close this one due to age. If this is still something you're interested in, please open a new issue.