In order to view request metrics for an AWS S3 bucket in CloudWatch, you first need to create a new CloudWatch account and set up your bucket. After creating your bucket, you can then use the following steps to view request metrics:
- In the CloudWatch console, open the Bucketwatch tab and select your bucket.
- In the Bucketwatch details pane, you will see a list of all the requests that have been made to your bucket since it was created. You can see how many requests were made and when they were made by looking at the Request Type field and the DateTime field. You can also see which resources were used for each request by looking at the Resource Type field and the Amount field.
- To view detailed information about a specific request, you can click on its Details button in the Bucketwatch details pane. This will show you all of the information about that particular request such as its source code, size, time taken, and more.
S3 comes with some basic analytics for bucket size and number of objects, which are free and calculated automatically. However, if you want to view more detailed analytics for S3 requests, you’ll need to turn on request metrics.
Enabling Metrics
In order to see request metrics, you’ll need to enable them for each bucket. These aren’t free like the default metrics — CloudWatch’s Paid Tier costs $0.30 per metric. Unfortunately, each S3 bucket can add up to 16 different request metrics, and they’re all on all the time. This brings the cost to $5 per bucket, potentially less depending on whether or not you use certain options.
To turn it on, head over to the Metrics tab for your bucket:
You’ll see the default metrics, and at the bottom, there’s a “View Additional Charts” button:
Click “Create Filter” to make a filter that will turn on request metrics.
You can limit this to a specific subset of items, or just select “This filter applies to all objects in the bucket.”
Once that’s done, request metrics will start being shipped to CloudWatch. It may take a little bit, so grab a coffee and come back to it.
Using Metrics in CloudWatch
Head over to the CloudWatch Management Console to get started.
You’ll need to create a new Dashboard, and add a widget to it. You can choose any kind of graph, but for simple request metrics, line charts generally work best.
For the metrics, select S3:
And then “Request Metrics Per Filter.”
You’ll then see a list of metrics available to you from the buckets you have request metrics enabled on. Two of the most useful are BytesDownloaded and BytesUploaded, which track raw data usage. You can graph them over time, and add this graph to your dashboard.
By default, the graph shows the average data usage. You’re probably interested in the total data usage, so under “Graphed Metrics,” you can change the statistic to “Sum,” which will total up all requests for the given period. This works best when set to a long period, like an hour or day.
Of course, like all CloudWatch metrics, you can set up automated alarms for when usage gets unexpectedly high, and also use those alarms for other events in your account.