- Newest
- Most votes
- Most comments
Here is the answer, AWS provides a WSGI HTTP Server which is Gunicorn for setting up a Python worker environment in beanstalk. Also, it provides a sample application, can be downloaded from here https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/tutorials.html (Python.zip) which can be used as a template and modify according to needs. We need to create a file named application.py with the following method:
def application(environ, start_response)
Here, within param 'environ' we can get all the values passed through HTTP request. There is no need to directly call any SQS or something like that.
Many years ago I created a small SQS lab which goes through sending and receiving messages and fortunately, it's written in Python. It might help here.
Update: The documentation talks about how Beanstalk consumes SQS messages - once they are read from the queue they are sent to http://localhost:80/ so you will need a process that listens on port 80 to receive the message.
Essentially this means you'll need to create a web server - there are many ways of doing that in Python. You might start here or here or even use something like Flask.
Relevant content
- AWS OFFICIALUpdated 5 years ago

Brett, thanks for your code repo. Here, you are using SQS URL and 'receive_message' function to get the message from SQS. But my scenario is something different, the Beanstalk daemon is already posting message to the application hosted in Beanstalk environment and the Python script within the application needs to grab that. So there is no need to use SQS name or URL explicitly because it's already posted by the daemon. But how to grab that, is there any specific object which script can access? I couldn't find any AWS documentation online.
Brett, we are not using any web server but using worker in beanstalk. Application is there within the worker and it needs to grab the SQS message posted by daemon without the help of any web framework. Is it possible?
If you set up a Beanstalk task that is not SQS specific then the Beanstalk environment won't try and consume the SQS messages for you - instead you can just run your code. That might be an option.