Farooq Butt
Farooq Butt

Reputation: 201

AWS Lambda function to start/stop Aurora Cluster

I am running an staging Aurora Cluster on AWS consisting of 1 writer and 1 reader with Engine version: 5.7.mysql_aurora.2.07.2.

Is there a way to schedule start/stop of aurora cluster via lambda ? The idea here is to save cost. I was able to schedule start/stop of my EC2 instance with lambda and cloudwatch rules with a cron expression. But i cannot find anything similar for my aurora cluster.

Upvotes: 0

Views: 1713

Answers (2)

Jatin Mehrotra
Jatin Mehrotra

Reputation: 11496

According to Docs starting and stopping Aurora cluster is possible using StartDBCluster and StopDBCluster api's

The document will redirect to API page.

I am choosing an example of boto3 API which can be used with lambda.

for starting aurora cluster.

response = client.start_db_cluster(
    DBClusterIdentifier='string'
)

for stopping aurora cluster

response = client.stop_db_cluster(
    DBClusterIdentifier='string'
)

For event scheduling i would recommend to use AWS Eventbridge along with Lambda.

Note :- you would need to Create an IAM Role and attach start stop Policy for lambda to access AWS aurora cluster

Upvotes: 1

Gunjan
Gunjan

Reputation: 1244

This option is available: Starting the cluster and Stopping the cluster

You can write lambda function like this:

import boto3

client = boto3.client('rds')

aurora_db_cluster = 'your-db-cluster-identifier'
response = client.stop_db_cluster(
    DBClusterIdentifier=aurora_db_cluster
)

response = client.stop_db_cluster(
    DBClusterIdentifier=aurora_db_cluster
)

Make sure lambda function has IAM rights to perform this action.

Upvotes: 3

Related Questions