skip to Main Content

Can someone help me with best solution to stop an RDS instance beyond 7 days . I can see that the common approach is to use lambda + cloudwatch event .

I came across Resource scheduler which is managed by AWS appears to be cost effective and easy to implement. But these RDS instances are provisioned manually via aws console and AWS Docs says, any resources that are not part of cloudformation stack will not be handled by Resource scheduler which makes it an impossible solution for me

https://docs.aws.amazon.com/managedservices/latest/appguide/ams-resource-scheduler.html

Am I on right track ?

2

Answers


  1. You should be able to use SSM – Simple Systems Manager – which has a AWS-StopRdsInstance automation predefined. Then you can schedule that automation with EventBridge Scheduler using the at() expression.

    The following example(from above docs) shows setting up sending an email to be sent at a specific time via the AWS CLI calling the EB Scheduler API – but i believe SSM automation’s are also supported with Universal Targets feature so you could use something similar?

    aws scheduler create-schedule --name SendEmailOnce  
    --schedule-expression "at(2022-11-01T11:00:00)"  
    --schedule-expression-timezone "Europe/Helsinki" 
    --flexible-time-window "{"Mode": "OFF"}" 
    --target "{"Arn": "arn:aws:sns:us-east-1:xxx:test-chronos-send-email", "RoleArn": " arn:aws:iam::xxxx:role/sam_scheduler_role" }"
    

    The StopRdsInstance document expects a Role with suitable permissions to shutdown the RDS, and the instance id of rds to shutdown. You’ll need to figure out the format based on the SSM automation api on how to execute automation documents with required parameters in the right format. (And of course you can use any AWS supported language SDK or the console as well as the CLI to create the schedules).

    Login or Signup to reply.
  2. You cannot stop RDS instances beyond 7 days. You can only temporarily stop RDS instances up to 7 days. In the 8th day it will start automatically. If you manually stop it again, then it will be temporarily stopped for another 7 days until you or anyone else with required permissions or by configured trigger it get started. This is the normal method that RDS behaves.

    Refer Step 4
    https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_StopInstance.html#USER_StopInstance.Stopping

    So the solution actually depends on your use case. Instance scheduler is a good solution but it has its downsides also. You can write custom codes using Lambda or Step Functions also but it you are not an coder this can be a hassle and hard to managed in long run.

    But as MisterSmith explained above, you can implement a AWS managed solution using AWS Systems Manager Automation, Maintenance Windows, tags and Event Rules.

    If you can explain bit about your requirement, I can help you with a proper solution. Hope this helps you.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search