Skip to content

Commit

Permalink
Add lifecycle rule for cleaning up noncurrent manifests
Browse files Browse the repository at this point in the history
See #192 for
rationale behind one day rule.
  • Loading branch information
mvandenburgh committed Dec 2, 2024
1 parent 222d455 commit ec50cee
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions terraform/modules/dandiset_bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,34 @@ resource "aws_s3_bucket_lifecycle_configuration" "expire_deleted_objects" {
status = "Enabled"
}
}

resource "aws_s3_bucket_lifecycle_configuration" "expire_noncurrent_manifest_files" {
# Must have bucket versioning enabled first
depends_on = [aws_s3_bucket_versioning.dandiset_bucket]

count = var.versioning ? 1 : 0

bucket = aws_s3_bucket.dandiset_bucket.id

# Based on https://docs.aws.amazon.com/AmazonS3/latest/userguide/lifecycle-configuration-examples.html#lifecycle-config-conceptual-ex7
rule {
id = "ExpireOldManifestFileVersions"
filter {
# We only want to expire objects with the `dandisets/` prefix, i.e. manifest files.
# Other objects in this bucket are not subject to this lifecycle policy.
prefix = "dandisets/"
}

# Only keep 1 noncurrent version of manifest files
noncurrent_version_expiration {
newer_noncurrent_versions = 1
}

# Also delete any delete markers associated with the expired object
expiration {
expired_object_delete_marker = true
}

status = "Enabled"
}
}

0 comments on commit ec50cee

Please sign in to comment.