rossco
rossco

Reputation: 533

Terraform - Enable Request Metrics on S3 bucket

Is it possible to enable Request Metrics on an S3 bucket via Terraform, either using the aws_s3_bucket resource or other?

Upvotes: 5

Views: 2221

Answers (2)

Egidijus Lenk
Egidijus Lenk

Reputation: 11

There is a Terraform resource for that: aws_s3_bucket_metric

You can emit "Request Metrics" for an entire bucket or create a filter to monitor a specific folder or file that has a specific tag.

Here is an example from Terraform docs:

resource "aws_s3_bucket" "example" {
  bucket = "example"
 }

resource "aws_s3_bucket_metric" "example-entire-bucket" {
 bucket = aws_s3_bucket.example.id
 name   = "EntireBucket"
}

EntireBucket is the name of a filter you will see in the AWS console - name it however you want (don't use spaces between words).

here is an example to monitor only the documents/ folder:

resource "aws_s3_bucket" "example" {
 bucket = "example"
}

resource "aws_s3_bucket_metric" "example-filtered" {
 bucket = aws_s3_bucket.example.id
 name   = "ImportantBlueDocuments"

 filter {
  prefix = "documents/"
 }
}

Note the prefix = "documents/" - this is where you set a folder you want to monitor.

example image

Read more on Terraform docs

Upvotes: 1

Vikyol
Vikyol

Reputation: 5625

You can use aws_s3_bucket_metric resource in Terraform. Passing the name attribute as EntireBucket enables request metrics for the bucket.

resource "aws_s3_bucket" "example" {
  bucket = "example"
}

resource "aws_s3_bucket_metric" "example-entire-bucket" {
  bucket = "${aws_s3_bucket.example.bucket}"
  name   = "EntireBucket"
}

Upvotes: 5

Related Questions