A Cloud Architect Company
RDS Instance
Amazon Web Services

How to Stop and Start RDS Instance Automatically using System Manager to save AWS bill

Introduction

AWS provides a fully managed Database service called RDS. What does mean the word fully managed. It has every things which are required to run a database in cloud and also we don’t need to worry about licensing. But there are some things that customers should be manage like availability of the database, choosing the right size of database engine, maintaining backups, cost optimization and so on.

If you want to know how to upgrade the RDS database with minimal downtime feel free to look the following links to know more.

Here we are going to discuss about Cost optimization with the run time of a database. For example, If you want to run your database instance only a certain time like 9 am to 9 pm. But manually start the database in morning 9 am and stop it in evening 9 pm is boring, right. Some times you forget to start the database and it will lead the application downtime in the working hours.

But if you setup an automation process which is stop and start the RDS database daily, at the time which you specified. Do you know how to do that? Don’t worry… Here is a solution that will give you a very simple end-to-end process.

AWS provides a service called System Manager, which is we are gonna use to stop and start our database. Let’s get into the details now.

Create IAM role and Policy for System Manager

  • In the AWS IAM console click create role.

  • Select the Trust entity type to AWS service and for Use cases, search for system manager and select it like the picture below.

  • Then click Next button.

Stop and Start RDS Instance Automatically using System Manager select service

Now Click on the Create policy button to create a new IAM policy.

Stop and Start RDS Instance Automatically using System Manager create policy

Copy the below code and paste it under the JSON editor and click Next:Tags followed by click Next button.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "rds:Describe*",
                "rds:Start*",
                "rds:Stop*",
                "rds:Reboot*"
            ],
            "Resource": "*"
        }
    ]
}

Stop and Start RDS Instance Automatically using System Manager Add Permissions

  • On the Policy Review page, Enter a name for your IAM policy like ‘StopStartRebootRDS’.

  • Then click Create policy.

Stop and Start RDS Instance Automatically using System Manager Create policy

  • Now navigate to the IAM Role page and click the refresh button.

  • And then search for stopstart and choose the IAM policy that you have created and click Next.

Stop and Start RDS Instance Automatically using System Manager Add policy

In the review page Enter role name like ‘StopStartRebootRDS’.

Stop and Start RDS Instance Automatically using System Manager Add Role Name

Scroll down to the bottom and you can able to see the attached permissions. Finally click Create role.

Stop and Start RDS Instance Automatically using System Manager Create Role

Create SSM Association for Stop RDS Instance

  • Navigate to the Systems Manager console and in the left side click the State Manager link under the Node management section.

  • Now click the Create an Automation button.

  • For Name enter StopInstanceRDS.

    Stop and Start RDS Instance Automatically using System Manager State Manager

  • Under Document section, search ‘AWS-Stop’ and choose the ‘AWS-StopRdsInstance’.

Stop and Start RDS Instance Automatically using System Manager State Manager Select Document

  • For execution choose Simple execution.

  • Under Input Parameters section, for InstanceId, you have to provide the name of the RDS instance which you want to stop and start periodically.

  • For AutomationAssumeRole, select the role which we have created the beginning of this blog.

Stop and Start RDS Instance Automatically using System Manager State Manager Select Execution

  • Under the Specify schedule section, Choose On Schedule.

  • For Specify with choose CRON schedule builder and followed by Daily. if you want to customize the timing for hourly you can select the Hourly type.

  • Enter the time when you want to trigger this manager to stop the database. This is using UTC time. So you have to provide the time in UTC.

  • Click the Apply association only at the next specified cron interval. otherwise it will triggered once this manager gets created.

  • Finally click the Create association button.

Stop and Start RDS Instance Automatically using System Manager State Manager Schedule to stop

Create SSM Association for Start RDS Instance

  • Now we have to create an Association document for Start RDS Instance.

  • For Name enter ‘StartInstanceRDS’.

  • Under Document section, search ‘AWS-Start’ and choose the ‘AWS-StartRdsInstance’.

Stop and Start RDS Instance Automatically using System Manager State Manager Select Document to start

  • For execution choose Simple execution.

  • Under Input Parameters section, for InstanceId, you have to provide the name of the RDS instance which you want to stop and start periodically.

  • For AutomationAssumeRole, select that StopStartRebootRDS role.

Stop and Start RDS Instance Automatically using System Manager State Manager Select Execution to start

  • Under the Specify schedule section, Choose On Schedule.

  • For Specify with choose CRON schedule builder and followed by Daily.

  • Enter the time in UTC when you want to trigger this manager to start the database.

  • Click the Apply association only at the next specified cron interval.

  • Finally click the Create association button.

Stop and Start RDS Instance Automatically using System Manager State Manager Schedule to start

Now you have successfully created Associations for Stop and Start RDS instance.

Stop and Start RDS Instance Automatically using System Manager Associations created

You can check the execution details. For this choose any on of the association and click the Execution history section.

Stop and Start RDS Instance Automatically using System Manager Association executions

Conclusion

Using this simple process will help you to automate your database run timings. And it saves the cost of the databases in dev and test environments when they’re not in use, thereby leading to a compute cost saving. However, keep in mind that although we’re stopping the databases, the storage costs for the databases still apply.

I hope this article is helps you to learn a new thing. If you have any doubts or needs any clarifications, feel free to comment it to below article. We will help you to clarify.

Article written by:

Jerin Rathnam is a proficient DevOps engineer who is dedicated to streamlining software development and deployment processes. He has extensive knowledge of cloud infrastructure, containerization, and CI/CD pipelines, which enables him to effectively connect development and operations. Jerin specializes in creating numerous Terraform modules for multi-cloud infrastructure and possesses immense expertise in configuring and managing cloud infrastructure. His profound understanding of containerization, along with his experience in orchestration tools like Docker and Kubernetes, further supports his skills as a valuable DevOps engineer.

Leave a Reply

Your email address will not be published. Required fields are marked *

back to top
advanced-floating-content-close-btn

Contact Us to save your AWS bill by 40%

X