Resource: aws_s3_bucket_metric

Provides a S3 bucket metrics configuration resource.

Example Usage

Add metrics configuration for entire S3 bucket

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

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

Add metrics configuration with S3 object filter

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/"

    tags = {
      priority = "high"
      class    = "blue"
    }
  }
}

Add metrics configuration with S3 object filter for S3 Access Point

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

resource "aws_s3_access_point" "example-access-point" {
  bucket = aws_s3_bucket.example.id
  name   = "example-access-point"
}

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

  filter {
    access_point = aws_s3_access_point.example-access-point.arn

    tags = {
      priority = "high"
      class    = "blue"
    }
  }
}

Argument Reference

This resource supports the following arguments:

The filter metric configuration supports the following:

Attribute Reference

This resource exports no additional attributes.

Import

In Terraform v1.5.0 and later, use an import block to import S3 bucket metric configurations using bucket:metric. For example:

import {
  to = aws_s3_bucket_metric.my-bucket-entire-bucket
  id = "my-bucket:EntireBucket"
}

Using terraform import, import S3 bucket metric configurations using bucket:metric. For example:

% terraform import aws_s3_bucket_metric.my-bucket-entire-bucket my-bucket:EntireBucket