ECS Cluster Hibernation-Scheduled Stop/Start

Reading Time: 3 minutes

35744588-b90c77b8-080e-11e8-8909-8729a71ff944

But Why?

Intensely utilized ECS Clusters can cost lots of Benjamins. Needless to say, there is no way around to lower the costs in Production environments besides provisioning appropriate type of instances for the tasks, coding efficiently, architecting a well-planned infrastructure and so on since the clusters must be running all the times. But of course an Infrastructure Engineer can take actions on Development environments to lower the costs.

I’m shutting down all clusters on Development environment between 23:00-07:00 in my way by a Python Lambda script which gets deployed by Terraform. I stop clusters by setting their Auto Scaling Group to 0. This makes all Container Instances to shut down. But what about the inital ASG states? Where do minimum, maximum and desired values go? I write them to a DynamoDB Table before setting them to 0.

I start the clusters by reading and setting the initial values for Cluster specific ASG from that DynamoDB Table.

For the schedule, I’m using CW Event Rules to trigger the Lambda script.

Let’s see the scripts!

Continue reading

Cloudwatch Agent Installation to EC2 Instances with Ansible

Reading Time: 2 minutes

amazon-cloudwatch

Prerequisites

In this post, I will be explaining how to install Cloudwatch Agent using an Ansible Controller Host machine which is used for initializing and provisioning other machines.

You will need:

  • Basic knowledge of Ansible
  • A Controller machine to run the playbook remotely
  • A Controller machine with Ansible installed
  • A Remote machine with SSH Daemon and Python interpreter installed
  • A Remote machine with proper Policy attached (Allowance for PutMetricData)
  • Make sure you have a proper configuration .json file, check here

Playbook

Using a Controller EC2 instance makes it easier to manage other instances since in this way, you don’t need to install Ansible each machine you manage because it works with SSH Daemon and an up-to-date Python interpreter.

Continue reading