Score:1

Deploy a PHP application that calls python scripts on AWS

in flag

I've made a PHP site that calls a bunch of python workers in the background (using the queue-worker system in laravel, where the worker calls the python tool via CLI). The python tools each have their own conda environment setup they need to run correctly.

I can run this setup quite well on a single server, because everything is installed on the machine, but I want to deploy this to the cloud (AWS) in a robust manner.

From what I read, Elastic Beanstalk is quite nice and easy to distribute PHP code, with support for deploying new versions and so on, but I cannot see how I could include my python code.

I should probably look into:

  • separating my python tools from the PHP server (with the new problem of "how do I call them then, and wait for their results?")
  • putting everything in a docker container, and rebuild that every time one of the tools or PHP needs an update (with the new problem of "how do I make it redundant")

What is your wisdom on deploying this kind of setup?

Score:1
cn flag

Elastic Beanstalk has support for various extensions/config via ebextensions, so you may well be able to zip up the python code and configure it via that.

As to seperating them, you're getting into the distributed system area. A common pattern is to write messages to a work queue (e.g. PHP -> AWS SQS), and have workers subscribe/consume from that queue and run the task. Results can be written to a database for retrieval. So you could have PHP write to SQS, convert the Python commands to Lambdas (depending on what they need to do), and write the results to DynamoDB. Then the results can be retrieved by the original PHP central server.

Or, with regards to making things redundant - you can move the stored-state part of your system to a database or central file system like EFS, and use tools like AWS ECS to run the container and connect to it.

There's potentially lots of ways to solve it, depending on cost/resiliency requirments/knowledge, etc.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.