Calling a command line app from a web app

I’ve written a command line app in Go which I now want to put a web front end on. As the app can take up to 10 seconds to run, I don’t want to just merge the code into a web framework and call it when the user clicks go, I want to use some kind of call out to the code as a separate app/thread/routine/whatever and then let the user know when the job is done so they can come back and view the results.

There is obviously the chance that the app will be called multiple times so, to avoid overloading the server, I want to have some kind of worker queue that jobs get placed in so no more than X jobs can be ran at once.

I can think of a few ways to do this but was wondering if there was any kind of framework already created for doing this. Any suggestions?

If I understand your use case, sounds like a pretty good use case for an AWS Lambda, or more specifically Serverless Framework.

This may or may not constitute, the following.

I don’t want to just merge the code into a web framework and call it when the user clicks go

But, effectively what you could do is use a lambda(s) as a http api for your command line application, from which you can build a front end around.

I hope this was useful.

1 Like

That sounds like part of it, but is there anything to help with tracking who owns what which jobs?

I can think of how to do it, but is there anything already written to manage calling lamdas. Not to actually call them, to manage the whole thing? Just trying to avoid reinventing the wheel.

That sounds like part of it, but is there anything to help with tracking who owns what which jobs?

I guess it depends to what extent, inherently, whoever makes the request into the lambda could be considered the owner.

If you mean in terms of managed permissions, AWS has a few services that you could use depending on where you want the permissions to be in the process.

If you decide to use Lambdas, you could control access to a REST API using AWS Cognito.

Thanks, I’ll have a look.

Thanks, I’ll have a look.

Alternatively, you could implement basic authentication with JSON Web Tokens in the Lambda, but you’re probably going to need a database which might be as you say, reinventing the wheel for your use case.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.