DEV Community

Rajit Paul
Rajit Paul

Posted on

2 1

Modify RDS Instance Type using Lambda during peak hours with Cloudwatch Events

Hi Folks, hope you are doing good.
Use-case: To modify RDS Instance Type to facilitate load during peak hours using Lambda and Cloudwatch Events

Create a Lambda Function:

  • Author from scratch
  • Function Name - your desired name
  • Runtime - Python 3.9
  • Architecture - x86_64
  • Permissions - Create a new role with basic Lambda Function

Code - (https://raw.githubusercontent.com/RajitPaul11/AWS-Lambda/main/RDS-DB-Modify/lambda_function.py)

Additional IAM Policy for RDS Modify Access:
Policy Json - (https://raw.githubusercontent.com/RajitPaul11/AWS-Lambda/main/RDS-DB-Modify/rds-modifyaccess-iam.json)

  • Add this as an inline policy to the Lambda Default Role

Amazon EventBridge (Cloudwatch Events):
Create a new rule
Rule Name - Desired Rule Name
Pattern - Schedule - Cron Expression (Cronex - 55 7 ? 2 7 * (Every Saturday at 7:55 GMT) - Choose your cron expression according to your requirement
Cron Expression Help - (https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html#CronExpressions)
Select Targets - Target - Lambda Function - Select your function.
Create Cloudwatch Event

We have automated the RDS Instance Type modification, the Cloudwatch Event shall trigger the Lambda Function at the desired time and modify the RDS Instance to an upgraded Instance type, you can also use this for downgrade db instance.

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay