Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Stop and Start AWS Fargate App (Task) based upon usage for cost saving?

Before you mark this question duplicate, I know there have been some questions asked about how to programmatically stop AWS Fargate Tasks when there are some technical issue with the task but my question is a little different.

I want to start and stop AWS Fargate Task based upon usage to save cost, i.e. when there is no traffic to the app, the ECS stops the Task and when there is some user accessing the app, the ECS starts the task. This will be helpful given that Fargate is pay-for-what-you-use kind of service.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

To start and stop AWS Fargate tasks based upon usage, you can use AWS Lambda and CloudWatch Events to monitor the incoming traffic to your application. Here is a high-level overview of how you can achieve this:

  1. Set up CloudWatch Events to monitor the incoming traffic to your application. You can create a rule that triggers an AWS Lambda function when there is incoming traffic to your application.

  2. In the AWS Lambda function, use the AWS SDK to start and stop the Fargate task. You can use the run_task API to start the task and the stop_task API to stop the task.

  3. Set up the AWS Lambda function to start the Fargate task when there is incoming traffic to your application and stop the task when there is no traffic. You can do this by checking the number of incoming requests to your application in a given time period. If the number of incoming requests is below a certain threshold, you can stop the Fargate task to save cost. If the number of incoming requests exceeds the threshold, you can start the Fargate task to handle the incoming traffic.

  4. Monitor the performance of your application to ensure that the Fargate task is started and stopped as expected. You can use CloudWatch Metrics to monitor the CPU usage, memory usage, and other performance metrics of your application.

By using this approach, you can save cost by only running the Fargate task when it is needed and stop it when it is not.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading