I’m not sure how exactly it would work. When there are no healthy ALB targets the ALB returns 503 error, hence your visitors would see an error page instead of your website. That may trigger a Fargate container start but that often takes tens of seconds, sometimes even over a minute. By the time your container is up your visitor is probably gone.
If you want a truly serverless website with zero idle costs you’ll have to implement it using API.
- Put your frontend files (HTML, CSS, JS) in S3
- Load your dynamic content through API
- Implement the dynamic functionality in Lambda functions
- Use API gateway to call the Lambdas
- The DB can be Aurora Serverless or DynamoDB On-Demand
This architecture costs nothing when idle and provides instant response to your visitors.
Update: if you still want to scale down the Fargate Service to 0 Tasks you can certainly do it through setting the Service’s
0. That can be done e.g. through aws-cli:
~ $ aws ecs update-service ... --service xyz --desired-count 0
If you want to do this in Dev I suggest you run this UpdateService either manually, or from a cron-job, or from a scheduled Lambda function. Either way you can set the task to
0 at night and back to
1 the next working day. That’ll be easier than relying on AutoScaling which may not be that reliable for very low traffic.
Hope that helps 🙂