- Newest
- Most votes
- Most comments
You can use Amazon Eventbridge for this purpose. You can define the Eventbridge rule in such a way that it triggers when this event type occurs for this resource. Then you could use the rule to initiate the notification though available mechanisms like Amazon SNS. While defining the rule in EventBridge, you could use a filter pattern using SourceType, SourceIdentifier/SourceARN and Event_ID to narrow down the scope to the event of your choice. For the EventBridge target, you could use a number of destinations like CloudWatch, SNS, etc. You could even use the EventBridge rule to trigger an SSM document to accomplish the follow up tasks that you want to do automatically.
See EventBridge documentation https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-events.html for further details.
Hope this helps.
Here is an example of how to do it with Terraform https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_event_subscription
Try event category - low storage
, this even triggers storage autoscaling
With storage autoscaling enabled, when Amazon RDS detects that you are running out of free database space it automatically scales up your storage. Amazon RDS starts a storage modification for an autoscaling-enabled DB instance when Free available space is less than or equal to 10 percent of the allocated storage.
For this purpose you can utilize Lambda. A Lambda function could be triggered by RDS DB Instance events for storage modification. The Lambda could then query the DB Instance storage size and you can either write a custom metric value and set up an alarm or alert to SNS directly from there.
Relevant content
- asked 3 years ago
- asked a year ago
- AWS OFFICIALUpdated 2 years ago
Thanks, I think this way is the best. Maybe you have some examples how to do this with terraform/terragrunt? Thanks in advance!
I do not have examples with terraform/terragrunt. But I am giving below a sample from one of the tasks I carried out recently. I wanted to manage a snapshot using a shell script on an EC2 instance whenever the snapshot is used for a restore operation. Maybe this will give you an idea how to use this process and then you should be able to apply in your environment.
{ "version": "0", "id": "abcd1234-08zz-bb22-1aa1-1234abcd3df6", "detail-type": "RDS DB Snapshot Event", "source": "aws.rds", "account": "123456789012", "time": "2032-66-55T21:18:24Z", "region": "us-east-1", "resources": ["arn:aws:rds:us-east-1:123456789012:snapshot:orcl-manual-2032099999"], "detail": { "EventCategories": ["restoration"], "SourceType": "SNAPSHOT", "SourceArn": "arn:aws:rds:us-east-1: 123456789012:snapshot:orcl-manual-2032099999", "Date": "2032-01-26T21:58:25.151Z", "Message": "Restored from snapshot orcl-manual-2032099999", "SourceIdentifier": "orcl-manual-2032019996", "EventID": "RDS-EVENT-0043", "Tags": { "auto-delete": "no" } } }
The pattern I used for triggering the EventBridge rule (when the given snapshot is used for a restore operation):
{ "detail-type": ["RDS DB Snapshot Event"], "source": ["aws.rds"], "detail": { "SourceType": ["SNAPSHOT"], "SourceArn": "arn:aws:rds:us-east-1: 123456789012:snapshot:orcl-manual-2032099999"
"EventID": ["RDS-EVENT-0043"] } }
SSM Run Command: Target: EC2 Instance where the target-cmd.sh script is located and needs to be run [This can be furnished using tag values or the instance-id itself]
Target input using an input transformer: Input Path: {"instance-id":"$.detail.SourceIdentifier"}
Template: {"commands": ["su - oracle -c "/home/myuser/target-cmd.sh <instance-id>""]}
Note: So, based on the above sample event, this input transformer would result in the followingoutput: {"commands": ["su - oracle -c "/home/myuser/target-cmd.sh orcl-manual-2032019996""]}
SSM: Run target-cmd.sh on the EC2 Given the sample output above, this will be the command executed on the target host: su - oracle -c "/home/myuser/target-cmd.sh orcl-manual-2032019996"
@Govardhanan_R, Maybe you know whether Lambda is needed for this setup? Or Eventbridge + SNS will be enough?