← All posts
2 min read

Enable S3 request metrics for a bucket

#aws#cli#s3#storage#observability#cloudwatch
📑 On this page

Part 69 of AWS from Zero. This lesson keeps the scope to one S3 behavior you can verify from the terminal.

What we are learning

S3 request metrics publish detailed operational metrics to CloudWatch for the configured filter scope.

Before you run it

aws sts get-caller-identity
REGION="ap-south-1"
BUCKET="replace-with-your-private-demo-bucket"

Use a private general purpose bucket that you own. Replace every placeholder before running a write or delete command.

Cost note: CloudWatch request metrics are billable custom metrics.

The command

aws s3api put-bucket-metrics-configuration \
  --bucket "$BUCKET" \
  --id EntireBucket \
  --metrics-configuration Id=EntireBucket

A successful configuration command may return no output. Treat inspection as a separate required step.

Inspect the result

aws s3api get-bucket-metrics-configuration \
  --bucket "$BUCKET" \
  --id EntireBucket

Read the returned fields rather than assuming the write succeeded exactly as intended.

One tiny variation

aws s3api list-bucket-metrics-configurations \
  --bucket "$BUCKET" \
  --query "MetricsConfigurationList[].Id" \
  --output text

List all IDs before adding or replacing configurations.

Common mistake

S3 daily storage metrics and request metrics are different. This configuration is for request metrics and can add CloudWatch metric cost.

Cleanup

aws s3api delete-bucket-metrics-configuration \
  --bucket "$BUCKET" \
  --id EntireBucket

Delete the demo metrics configuration.

Next, we will learn Configure S3 Storage Class Analysis.

Official AWS CLI reference