If you’re serving up a static website from S3, especially if you have larger assets stored there, you may want to put monitoring on the requests or bytes downloaded from S3, just to make sure someone’s not running up terabytes of transfers or millions of requests.
Enabling Metrics on S3
You will have to enable metrics on S3 in order to get CloudWatch alarms on them.
- Go to Services -> S3 -> Buckets and select the bucket for your static site.
- Select Management tab and [Metrics] and then click on the pencil icon next to the bucket icon.
- Once enabled, the metrics will take a bit to populate.
Setting up Simple Notification Service (SNS)
(These are the same instructions as in Monitoring your CloudFront #omgcat usage)
Set up a topic
- First, you’re going to want to be notified. Go to Services -> Simple Notification Service to set up a pathway for that to happen.
- Next, click “Topics” and then [Create topic]
- Name your topic something that adequately describes the purpose (I just used domainname-com)
- Scroll down to [Create Topic]
Set up a subcription
- Under “Amazon SNS” left sidebar, click “Subscriptions” and [Create Subscription]
- Click on the Topic ARN field and you should be able to see an ARN with your topic name as the last part of the ARN. Click that ARN
- Under Protocol, select your preferred method of notification (I’m going with SMS.
- Under Endpoint, enter your cell number, including country code (+18005551212 for (800) 555-1212 in the US)
Setting up a CloudWatch Alarm
- Go to Services -> CloudWatch -> Alarms and [Create alarm]
- [Select metric] and select S3
- If you don’t see “Request Metrics per Filter” then the metrics haven’t started populating yet.
- Check “GetRequests” or “BytesDownloaded” and [Select Metric]
- Set conditions as you would like to have flag any anomalies and click [Next]
- Choose “In Alarm” and “Select an existing SNS topic” and click in the box below “Send Notification To…” to get suggestions and select the SNS topic corresponding to the notification method you set up. Click [Next]
- Name your alarm and click [Next]
- Review the summary and click [Create Alarm]