Skip to content

Commit

Permalink
Merge pull request #199 from dandi/expire-noncurrent-manifest-files
Browse files Browse the repository at this point in the history
Manifest file garbage collection
  • Loading branch information
mvandenburgh authored Jan 2, 2025
2 parents cd43975 + 744e744 commit c2717f0
Show file tree
Hide file tree
Showing 3 changed files with 39 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 && var.enable_manifest_file_expiration ? 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"
}
}
7 changes: 7 additions & 0 deletions terraform/modules/dandiset_bucket/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@ variable "log_bucket_name" {
type = string
description = "The name of the log bucket."
}

# TODO: remove this after it's ready to be enabled in production
variable "enable_manifest_file_expiration" {
type = bool
description = "Whether or not to enable expiration of manifest files."
default = false
}
1 change: 1 addition & 0 deletions terraform/staging_bucket.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module "staging_dandiset_bucket" {
aws = aws
aws.project = aws
}
enable_manifest_file_expiration = true
}

module "staging_embargo_bucket" {
Expand Down

0 comments on commit c2717f0

Please sign in to comment.