Search code examples
amazon-web-servicesamazon-s3alertamazon-cloudwatchcloudcustodian

Alert or monitor, when your s3 bucket hits 90% of max limit for the particular account


We recently hit the limit for max no of s3 buckets in our AWS account. We started to look for something which sends alerts when we use 90% s3 buckets quota in our account. But we not been able to find no such metric in cloud watch. Also, we looked for a similar rule in cloud custodian but no luck.

Expected result:

If S3 bucket account limit is 100 for an account.

If a number of buckets reach 90 we expect an alert to be sent "90% of buckets quota used".

Is this scenario possible?


Solution

  • You could set up a Cloudwatch Event to pick up (via CloudTrail calls) every time a bucket is created in S3, which you could then use to trigger a lambda function which counts the buckets, and then sends a notification to SNS to notify whoever or whatever to take action. In Python (boto3) this would look something like:

    import boto3
    
    s3 = boto3.client('s3')     
    number_of_buckets = len(s3.list_buckets()['Buckets'])
    if number_of_buckets >= 90:
       # send an alert via SNS     
    

    Instead of using a Cloudwatch Event from the API you could also trigger the lambda on a cron schedule (eg once a minute or daily etc)