3

I am running an R ShinyApp on Fargate ECS. It is roughly used once per week by the customer. It is running constantly and therefore we are paying for a substantial amount of idle time.

Is there a way it could be launched when there is an incoming connection and then stopped when this connection ends?

Does anyone have any suggestions for this?

Many thanks

MGJ-123
  • 614
  • 4
  • 19
  • Fargate is not a good choice for long running tasks. What do you mean by a connection? You could use api gateway that triggers a lambda that starts a Fargate Task. – Radu Diță Apr 27 '20 at 15:18
  • 1
    @RaduDiță please site your reasons for stating Fargate is not a good choice for long running tasks. It is a perfectly good choice for running long-lived ECS services in my experience. – Mark B Apr 27 '20 at 15:21
  • 1
    To the original question, you can't just spin up an ECS container to handle a connection as a connection comes in. It takes several minutes for an ECS container to spin up, and during that time there is nothing available to handle the connection. You need a service actively running and listening for a TCP connection in order to handle the connection. The best you could do is have your user hit another endpoint to trigger the container to deploy, and have them wait several minutes before trying to connect. – Mark B Apr 27 '20 at 15:23
  • @MarkB I wasn't specific at all. I was talking from a cost perspective. From my knowledge it is cheaper to have an EC2 with docker on it instead of Fargate. – Radu Diță Apr 27 '20 at 15:31
  • 2
    Fargate costs have come down a lot. If a docker container doesn't need all the resources of the EC2 host, then over-provisioned EC2 hosts can be more expensive than Fargate, and it also adds the man-hours cost of provisioning and managing an EC2 instance. – Mark B Apr 27 '20 at 15:37

1 Answers1

2

You need a serverless style of application hosting, e.g. as suggested by a commentor with API Gateway backed by Lambda. If your request count is low, you may actually not pay much due to Free tier for these services. There is an R Runtime for Lambda here:

[1] Serverless execution of R code on AWS Lambda - https://github.com/bakdata/aws-lambda-r-runtime

shariqmaws
  • 8,152
  • 1
  • 16
  • 35