1
votes

The core of my question is whether or not there are downsides to using an Amazon Machine Image + Micro Spot instances to run a task, vs using the Elastic Container Service (ECS).

Here's my situation: I have the need to run a task on demand that is triggered by a remote web hook.

There is the possibility this task can get triggered 10 times in a row, or go weeks w/o ever executing, so I definitely want a service that only runs (and bills) on demand.

My plan is to point the webhook to a Lambda function, but then the question is what to have the Lambda function do.

Tho it doesn't take very long, this task requires several different runtimes (Powershell Core, Python, PHP, Git) to get its job done, so Lambda isn't really a possibility as I'd hit the deployment package size limit. But I can use Lambda to kick off the job.

What I started doing was creating an AMI that has all the necessary runtimes and code, then using a Spot request to launch an instance, have it execute the operation via a startup script passed in via userdata, then shut itself down when it's done. I'd have to put in some rate control logic to prevent two from running at once, but that's a solvable problem.

I hesitated half way through developing this solution when I realized I could probably do this with a docker container on ECS using Fargate.

I just don't know if there is any benefit of putting in the additional development time of switching to a docker container, when I am not a docker pro and already have the AMI configured. Plus ECS/Fargate is actually more expensive than just running a micro instance.

Are these any concerns about spinning up short-lived (<5min) spot requests (t3a-micro) where there could be a dozen fired off in a single day? Are there rate limits about this? Will I get an angry email from AWS telling me to knock it off? Are there other reasons ECS is the only right answer? Something else entirely?

1
I cannot directly answer for this question, but I can tell you for the spot instances, even if you terminate it you will pay the hour fee. If you already put everything together it is not a big jump to make a docker image from it. You have to measure the execution time of the task, and calculate the price based on this. Fargate bills you based on seconds. I know not the easiest task to estimate the price.Sándor Bakos

1 Answers

1
votes

Your solution using spot instance and AMI is a valid one, though I've experienced slow times to get a spot instance in the past. You also incur the AMI startup time.

As mentioned in the comments, you will incur a minimum of 1 hour charge for the instance, so you should leave your instance up for the hour before terminating, in case more requests can come in the same hour.

IMHO you should build it all with lambda. By splitting the workload for each runtime into its own lambda you can make it work.

AWS supports python, powershell runtimes, and you can create a custom PHP one. Chain them together with your glue of choice, SNS, SQS, direct invocation, or Step Functions, and you have the most cost effective solution. You also get the benefits of better and independent maintenance for each function/runtime.

Put the initial lambda behind API gateway and you will get rate limiting capabiltiy too.