Search code examples
amazon-web-servicesamazon-s3aws-lambdaterraformamazon-kinesis

Add tags to s3 objects dynamically to apply s3 life cycle rules


I have below s3 lifecycle rule created for existing s3 bucket. It should not be changed. I am sending the logs from kinesis firehose to s3 bucket as parquet formatted objects. Is there any way or option to add tags to that objects before storing to s3 to apply the life cycle rule.

resource "aws_s3_bucket_lifecycle_configuration" "testing" {
  bucket = "lifecycle-testing"
  rule {
    id     = "S3Intelligent1Yr"
    status = "Enabled"

    expiration {
      days = 365
    }

    transition {
      days          = 0
      storage_class = "INTELLIGENT_TIERING"
    }
    filter {
      tag {
        key   = "S3Intelligent1Yr"
        value = "Yes"
      }
    }
  }
}

Any idea or suggestion would be helpful.


Solution

  • You have to setup Amazon S3 Event Notifications in a form of lambda functions. The function will be automatically triggered for new parquet files, and you will add the tags to those objects.