1

From the following link, it seems possible to call a Fargate task from the API Gateway: https://aws.amazon.com/blogs/compute/introducing-amazon-api-gateway-private-endpoints/

But, does the task have to be running 24/7 for this to work? Is it possible to have the task run only when the endpoint is hit? I have some critical but rarely used services and I'd like to make them as inexpensive as possible.

I believe something similar is possible with Gateway + Lambda: https://serverless.com/blog/flask-python-rest-api-serverless-lambda-dynamodb/

But, I like the flexibility and ease of use which comes with using Docker and Fargate.

1 Answers1

1

Short answer: no, it's not possible.

  • When no Fargate task is running the API GW has nowhere to send the request and returns an error.

  • There may be a way to trigger a lambda from API GW when no task is running and start one up, however...

  • Fargate container takes time to start - tens of seconds at least, sometimes over a minute. It would be a poor user experience if their initial request took a minute to return.

Also check this out: AWS Fargate service: scale to zero?

Use Lambda, that's the correct way to do what you want.

Hope that helps :)

MLu
  • 23,798
  • 5
  • 54
  • 81
  • thanks! Do you have a preferred way to run docker on lambda? I saw this: https://hackernoon.com/how-did-i-hack-aws-lambda-to-run-docker-containers-7184dc47c09b -- i suppose another option is to use elastic beanstalk – matthewatabet Apr 21 '20 at 14:21
  • @matthewatabet you **don't run docker in Lambda** - as the linked article says *It's not a good idea* for many reasons. The most obvious one is start up time - it takes time to download and start the docker image which means your API will time out or at least be very slow to respond. Instead **run your Node.JS / PHP / Java / Python code directly in Lambda** - that's the way Lambda is meant to be used. Forget docker for your usecase. – MLu Apr 21 '20 at 21:39
  • Yeah, I think I'm looking for a "silver bullet" -- the thing is, I need to support a wide range of application developers with very little infrastructure. Docker is nice because they can each have their own set of system libraries. – matthewatabet Apr 23 '20 at 14:20
  • @matthewatabet Come on, the smallest size Fargate container on *spot* costs $2.75/month, even *on demand* it’s only $8.90/month. What’s the *Return On Investment* on your time spent on reducing this already minimal cost? Just run your stuff in Fargate if it’s not ready for Lambda. – MLu Apr 24 '20 at 23:03