Score:0

What's the best way to deploy large numbers of low-throughput docker containers on AWS?

fi flag

What's the best, simple way of deploying a lot of containers to AWS? It's necessary to be scalable but cheap if a container sees little or no use.

I have a method of generating docker containers that serve data (using fastAPI). Each container runs some basic numpy/ML, nothing too intensive. More importantly, they might not receive any requests for days on end, we need to able to deploy lots of these for minimal cost and not worry about keeping a whole EC2 instance up for them.

Appreciate anyone with an opinion on docker & AWS. Here's my understanding of the solutions (and why I'm not satisfied with them):

  • Elastic Beanstalk

This means uploading your container to ECR, then setting up a load-balancer environment on EB with an endpoint. This is the current solution I use, it's inconvenient that it's endpoint is a public URL, but I've already gone through the challenge of getting that on my virtual cloud. However, I suspect that while this can scale up as it needs to, it always keeps at least one EC2 instance running per container, which means paying like 1000x the cost of what you actually need, maintaining an EC2 instance that just sits there.

  • EC2 instances

I can just deploy an EC2 instance and run my containers on there. But this seeems extremely manual in terms of load (how many containers can fit on one instance?) and in terms of endpoints (I'd have to track the name and assign each container its own port), which seems messy and error prone.

  • Lambda Function uploaded as docker container

This means altering the docker container to implement a lambda_function method as it's api, then deploying it as a lambda function. This seems to be the only way to maintain containers in a zero-use means zero-cost (or minimal cost) fashion, paying only as requests come in. But, it means modifying the container for this use case and setting up a bunch of extra plumbing; I've got to somehow meld the typical lambda function dockerfile with my current web-api based dockerfile, and work out how to translate API Gateway requests into docker-lambda invocations.

  • Lambda Function, no longer using docker at all

Now I've completely deconstructed the docker containers, but maybe docker is just the wrong thing to use if you need 24/7 access but don't want to keep them running?

Conclusion

So basically I suspect I need to morph my containers into lambda-functions, which is doable but kind of defeats the purpose of having our contractors use docker (I'm now modifying the build procedure in a way that fits with my target environment, the exact thing docker is supposed to prevent!)

Tim avatar
gp flag
Tim
As you've pretty much worked out yourself, lambda functions may be the best way to do this. Any hosting using ECS Fargate / EC2 will cost money when it's idle.
Paranoid Altoid avatar
fi flag
Makes sense. I'll think about whether I can use the fastAPI docker build with lambda somehow, or if I should forget it. Speculating, containers take up a lot of space take a while to startup, so a lambda function that, say, uses docker run on each invocation might be inefficient. Maybe it's good enough having a python function that does "docker run" equivalent on import and uses the docker api in lambda_function would be okay if I understand lambda, doing docker run once if 100 invocations happen in a minute, and sleeping if not invoked for days.
Tim avatar
gp flag
Tim
Can you package the code directly for lambda, rather than using containers? Lambda SnapStart might help startup speed, though I'm not sure if it covers docker to start with as it's fairly new https://aws.amazon.com/blogs/aws/new-accelerate-your-lambda-functions-with-lambda-snapstart/
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.