Unveiling the new chapter: SecurDI’s brand refresh journey – Read the blog!
#nowhiring for multiple positions in USA, CANADA & INDIA  See Open Positions

Learn How to slash your AWS Bill

Streamlining and Optimizing AWS Operations

Product: AWS

An easy-to-use event trigger and script implementation that clients can use to automate boot and backup operations of servers in their AWS environment and streamline processes. Maintains good security hygiene and ensures optimum utilization of your resources.

Problem Statement: At the end of each work day, the customer wants the instances that aren’t critical to the business to be shut down and restarted the next day automatically. Currently, the client performs the tasks manually, which might lead to errors in the process, and it can be tedious and time-consuming; if not completed, the costs of AWS instances would skyrocket.

With the help of this automation solution, clients can:

  • Significantly reduce the level of manual effort by 70%
  • Reduce the support on the operations team by 90%
  • Reduce the scope of manual error by 100%
  • Reduce the costs of operations drastically by 60%
  • Bulk backup of data. Reduce the effort of the operation team by 95%

Use Case:

Scenario:  Client ABC has set up its corporate resources on AWS EC2. They have an Active Directory environment and database resources on the cloud. The customer accesses the cloud infrastructure during business hours, with monthly maintenance on the first Saturday of each month. The client must manually perform daily tasks – start/stop running instances and conduct periodic reboot operations.

Solution: To assist clients in achieving the use mentioned earlier, Amazon offers two functionalities: EventBridge and Lambda. AWS consultants from SecurDI have built a Lambda script leveraging Python AWS SDK, which takes instance ids as input and performs the start/stop operation when triggered using AWS EventBridge. Furthermore, it calculates when and how frequently to conduct the procedure depending on the cron expression. Doing this saves time and effort and significantly decreases server costs.

Operational Efficiency: This automation solution eliminates the possibility of manual error and increases overall efficiency. For environments operating at a larger scale, it becomes a huge administrative challenge to keep track of and manage AWS instances. Apart from saving time and effort, it also provides the client with a better understanding and view of which servers should run all the time and which should not. Organizations must use automated solutions since an error might jeopardize high availability or raise operating costs.

Additional Functionalities: The solutions as mentioned earlier are not limited to start/stop instances but can provide various other functionalities by modifying the script, such as:

  • Perform periodic reboots of EC2 Instances
  • Perform regular snapshots of EC2 Instances
  • Perform occasional restoration of EC2 states

Sample Python Script for Stopping Instance:

import boto3
ec2 = boto3.resource('ec2')
def lambda_handler(event, context):
filters = [{
'Name': 'tag:shutdown',
'Values': ['shutdown']
 'Name': 'instance-state-name', 
  'Values': ['running']

  instances = ec2.instances.filter(Filters=filters)
RunningInstances = [instance.id for instance in instances]

if len(RunningInstances) > 0:
shuttingDown = ec2.instances.filter(InstanceIds=RunningInstances).stop()
print("Nothing to see here")

For all the servers which come under policy add shutdown to the tags.

Sample Python Script for Starting Instances:

import boto3
region = 'us-east-1'
instances = ['i-id1', 'i-id2']
ec2 = boto3.client('ec2', region_name=region)

def lambda_handler(event, context):
print('started your instances: ' + str(instances))

Replace instances id with your actual instance ids. Change region to your AWS account region.

How SecurDI can help?

SecurDI is a team of well-rounded professionals with extensive experience in providing unique strategies, best implementation techniques and superior operational services. We have worked on many complex projects. When it comes to cloud-based solutions, our experts ensure that you implement the best fit solution that helps streamline processes and make optimal use of resources.

Document References:


Authored By,
Animesh Tarodia and Kartik Bagade