Reputation: 533
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
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.
Read more on Terraform docs
Upvotes: 1
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