0

This is a very inexperienced question. I've only ever deployed/hosted web applications so I don't understand what the system would have to look like if I want a CLI-like program hosted for anyone else to run.

It is a python script and I want it on AWS (probably will use a docker container, ECS, and terraform. So I suppose this is mainly a question about how to build the image).

The script takes flags/commands, runs while terminal printing for a few minutes, and then stops once finished. How do I host/build this so that anyone can access it through their shell/terminal? Is some sort of server akin to a http server required? There is no front end for it. And ideally many people can run this at once at any time.

EDIT: correction, there is no web GUI frontend... I add this to clear-up my loose use of these terms. Is this in principle an API?

4
  • 1
    The fact that it is a cli it does not mean that there is no front and back end, the dockerized part should be the server and the clients could be normal python apps Commented Jan 28, 2022 at 13:47
  • Thanks for clearing up my misuse of those terms. So imagine that you have a simple python script that counts to 10, and that you want it on cloud so that anyone can run it + many can at the same time... What would be the backend/frontend of this? @SecurityObscurity Commented Jan 28, 2022 at 13:49
  • 1
    Since you want to use python I would recommend a flask API as the backend with a database of your choice incase you want persistance , the front end part would also be a python application that would be responsible for consuming the API data, keep in mind that alot of things can occur in the development if you do not address them before starting, an example would be authentication/authorization Commented Jan 28, 2022 at 13:52
  • Who or What would trigger this script and provide the input parameters? Commented Jan 28, 2022 at 20:53

1 Answer 1

1

I would encourage you to look into AWS Lambda for something like this. AWS Lambda allows you to run code (including Python) without having to think about the servers are configured. One of the main benefits is you only pay for the time the software is actually executing, rather than paying for a Virtual Machine running idle.

As you mention, if you want to move towards an 'API' design where other users can call your service, you can use Amazon API Gateway in front of the Lambda code to handle this. There are really good examples of these design patterns here: https://serverlessland.com/patterns

Something like this one: https://serverlessland.com/patterns/apigw-lambda-cdk sounds like what you are looking for, but as mentioned by SecurityObscurity, you will need to think about authentication and authorisation. This could be handled by AWS Cognito or IAM authorisation depending on your use case.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for the suggestion! It's starting to make a bit more sense. Another question: would you still suggest this for scripts that run infinitely and would stop with a user interrupt? Is this even possible -- when I think API I think of the basic GET/POST/DELETE, etc, operations which return a single responses once but maybe there's something I don't know of @Ian-B
@KROM, it sort of depends on exactly what your script is doing. If it truly is a process that needs to run infinitely, then Lambda is not the right solution. It has a maximum runtime of 15 minutes, and it really designed for short running, discrete tasks. If there is no way to split your function up into these kinds of tasks, then yes, something like a docker container running on ECS might be the best option. You could still use API Gateway / Lambda as a REST front end to handle the instructions to start, stop, pause, get status etc. of your process running on ECS.
It doesn't need to run infinitely. It's a process that is started and needs to continue until the user wants a specific block/index, which is an amount that will vary every time. It's particularly important to see live outputs of the script as it runs. Whether it's lambda or ecs or whatever I will decide later. Part I'm particularly lost about is how to stream the output to the user (without it being a script on a host one ssh's into and watches run on the terminal). What is this called?
OK, it does sound like what you are looking for is a websocket rather than a REST interface. This is supported by AWS API Gateway and there is some documentation here: docs.aws.amazon.com/apigateway/latest/developerguide/…
Another (potentially simpler) option is to have a REST API with a GET endpoint that fetches latest output from the script that is running remotely. This could be queried at regular intervals by your client(s). This is not an ideal pattern as the clients will be responsible for repeatedly querying, but depending on your need, could be easier to set up.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.