Guide · Amazon S3 · Lifecycle Policies · Storage Classes · MCP Server Tools

S3 Lifecycle Policies for MCP Servers — Transition Rules, Expiry, Intelligent-Tiering

MCP server tools generate storage objects across a range of access patterns: a user-uploaded file is downloaded frequently in the first 7 days, then rarely; a system-generated report is needed for 90 days for compliance, then can be deleted; a temporary processing artifact should be cleaned up automatically after 24 hours. Without lifecycle policies, all of these objects stay in S3 Standard at full price indefinitely. S3 lifecycle policies automate three operations: transitioning objects to cheaper storage classes as they age, expiring objects permanently, and aborting incomplete multipart uploads. This guide covers writing lifecycle rules with the AWS SDK, the storage class transition graph with minimum duration constraints, prefix and tag-based filtering, versioned bucket rules, and common pitfalls.

TL;DR

Use PutBucketLifecycleConfigurationCommand to set rules. Each rule needs an ID, Status: 'Enabled', a Filter (prefix or tag), and at least one action (Transitions, Expiration, or AbortIncompleteMultipartUploads). Minimum duration before first transition is 30 days for Standard→Standard-IA, 30 days for Standard→Glacier Instant Retrieval, and 90 days for Standard→Glacier Flexible. S3 Intelligent-Tiering has no minimum duration requirement and no retrieval fees for Frequent/Infrequent tier — use it for unpredictable access patterns. Always add an AbortIncompleteMultipartUploads rule (7 days) to avoid orphaned-upload charges.

Storage class comparison for MCP server workloads

Storage classUse caseMin durationRetrieval
S3 StandardFrequently accessed objects, latency-sensitiveNoneMilliseconds, free
S3 Standard-IAInfrequently accessed, accessed in full30 daysMilliseconds, per-GB fee
S3 One Zone-IANon-critical infrequent access, single AZ30 daysMilliseconds, per-GB fee
S3 Intelligent-TieringUnknown/variable access patternsNoneMilliseconds (Frequent/Infrequent), minutes (Archive)
S3 Glacier Instant RetrievalArchival data accessed once per quarter90 daysMilliseconds, per-GB fee
S3 Glacier Flexible RetrievalArchival data, 1–5 minute or bulk retrieval90 days1–5 min (expedited), 3–5h (standard), free bulk
S3 Glacier Deep ArchiveCompliance archives, rare retrieval180 days12h (standard), 48h (bulk)

Minimum duration billing: If you transition an object to Standard-IA after 30 days and then delete it at day 45, S3 bills you for 30 days of Standard-IA storage regardless — the minimum duration is a billing commitment, not a hard lock. Factor this into cost modeling for short-lived objects.

Basic lifecycle rule with the SDK

The SDK method is idempotent: calling PutBucketLifecycleConfigurationCommand replaces the entire lifecycle configuration. To add a rule, read the existing configuration first, append your rule, then write the whole list back. Or manage the full configuration from infrastructure-as-code.

import {
  S3Client,
  PutBucketLifecycleConfigurationCommand,
  GetBucketLifecycleConfigurationCommand,
} from '@aws-sdk/client-s3';

const s3 = new S3Client({ region: 'us-east-1' });

await s3.send(
  new PutBucketLifecycleConfigurationCommand({
    Bucket: 'your-mcp-bucket',
    LifecycleConfiguration: {
      Rules: [
        // Rule 1: Expire temporary processing files after 1 day
        {
          ID: 'expire-temp-files',
          Status: 'Enabled',
          Filter: { Prefix: 'tmp/' },
          Expiration: { Days: 1 },
        },

        // Rule 2: Transition user uploads to Standard-IA after 30 days, Glacier after 90
        {
          ID: 'archive-user-uploads',
          Status: 'Enabled',
          Filter: { Prefix: 'uploads/' },
          Transitions: [
            { Days: 30, StorageClass: 'STANDARD_IA' },
            { Days: 90, StorageClass: 'GLACIER_IR' }, // Glacier Instant Retrieval
          ],
          Expiration: { Days: 365 }, // delete after 1 year
        },

        // Rule 3: Safety net for abandoned multipart uploads
        {
          ID: 'abort-incomplete-multipart',
          Status: 'Enabled',
          Filter: { Prefix: '' }, // apply to all objects
          AbortIncompleteMultipartUploads: { DaysAfterInitiation: 7 },
        },
      ],
    },
  })
);

Filtering by tag

When you need lifecycle rules that cut across prefixes — based on data classification, tenant, or retention class — use tag filters. Set the tag on the object at upload time and reference it in the lifecycle rule.

import { PutObjectCommand } from '@aws-sdk/client-s3';

// Upload with lifecycle tag
await s3.send(
  new PutObjectCommand({
    Bucket: 'your-bucket',
    Key: 'reports/2026-11-12-audit.pdf',
    Body: pdfBuffer,
    ContentType: 'application/pdf',
    Tagging: 'retention=90days&classification=audit', // URL-encoded tag string
  })
);

// Lifecycle rule using tag filter
await s3.send(
  new PutBucketLifecycleConfigurationCommand({
    Bucket: 'your-bucket',
    LifecycleConfiguration: {
      Rules: [
        {
          ID: 'expire-90day-retention',
          Status: 'Enabled',
          Filter: {
            Tag: { Key: 'retention', Value: '90days' },
          },
          Expiration: { Days: 90 },
        },
        // Combining prefix AND tag with And filter
        {
          ID: 'archive-audit-reports',
          Status: 'Enabled',
          Filter: {
            And: {
              Prefix: 'reports/',
              Tags: [{ Key: 'classification', Value: 'audit' }],
            },
          },
          Transitions: [
            { Days: 30, StorageClass: 'STANDARD_IA' },
            { Days: 180, StorageClass: 'DEEP_ARCHIVE' },
          ],
        },
      ],
    },
  })
);

Tag filter performance: S3 evaluates lifecycle rules nightly in a background job, not in real-time. Object deletion or transition happens on a best-effort basis within 1–2 days of the lifecycle rule triggering. Don't rely on lifecycle expiry for security-sensitive deletion — use DeleteObject explicitly.

Versioned bucket lifecycle rules

When versioning is enabled, deleted objects become noncurrent versions rather than being removed. Without lifecycle rules for noncurrent versions, your bucket accumulates versions indefinitely. Add rules to expire noncurrent versions and delete expired delete markers.

await s3.send(
  new PutBucketLifecycleConfigurationCommand({
    Bucket: 'your-versioned-bucket',
    LifecycleConfiguration: {
      Rules: [
        {
          ID: 'manage-noncurrent-versions',
          Status: 'Enabled',
          Filter: { Prefix: '' },

          // Transition noncurrent versions to cheaper storage
          NoncurrentVersionTransitions: [
            { NoncurrentDays: 30, StorageClass: 'STANDARD_IA' },
            { NoncurrentDays: 90, StorageClass: 'GLACIER_IR' },
          ],

          // Keep only the 3 most recent noncurrent versions, expire older ones
          NoncurrentVersionExpiration: {
            NoncurrentDays: 180,
            NewerNoncurrentVersions: 3, // keep the 3 most recent noncurrent versions
          },

          // Remove expired delete markers (markers with no object versions left)
          Expiration: { ExpiredObjectDeleteMarker: true },
        },
      ],
    },
  })
);

NewerNoncurrentVersions was added in 2022 and is the cleanest way to cap version history depth. Setting it to 3 means: keep the current version + the 3 most recent noncurrent versions; expire anything older. This prevents unbounded version accumulation for objects that are updated frequently by MCP tools.

S3 Intelligent-Tiering configuration

S3 Intelligent-Tiering automatically moves objects between access tiers based on observed access patterns — no need to predict access frequency. For MCP server workloads where access patterns are genuinely unpredictable (AI-generated content that might be accessed once or a hundred times), Intelligent-Tiering is often the best default.

import { PutBucketIntelligentTieringConfigurationCommand } from '@aws-sdk/client-s3';

// Enable Intelligent-Tiering configuration on the bucket
await s3.send(
  new PutBucketIntelligentTieringConfigurationCommand({
    Bucket: 'your-bucket',
    Id: 'default-intelligent-tiering',
    IntelligentTieringConfiguration: {
      Id: 'default-intelligent-tiering',
      Status: 'Enabled',
      Filter: { Prefix: 'generated/' }, // apply to AI-generated content
      Tierings: [
        // After 90 days without access: move to Archive Instant Access (68% savings)
        { Days: 90, AccessTier: 'ARCHIVE_ACCESS' },
        // After 180 days without access: move to Deep Archive Access (95% savings)
        { Days: 180, AccessTier: 'DEEP_ARCHIVE_ACCESS' },
      ],
    },
  })
);

// Upload to Intelligent-Tiering directly
await s3.send(
  new PutObjectCommand({
    Bucket: 'your-bucket',
    Key: 'generated/output-123.json',
    Body: jsonBuffer,
    StorageClass: 'INTELLIGENT_TIERING', // start in Frequent Access tier
  })
);

Intelligent-Tiering has a monitoring fee per object per month (applies to objects > 128 KB). Objects smaller than 128 KB or stored for less than the minimum duration are not cost-effective for Intelligent-Tiering. For small, short-lived objects, use Standard with explicit lifecycle expiry instead.

Reading and updating lifecycle configuration

Since PutBucketLifecycleConfigurationCommand replaces the entire config, you need to read first before adding rules programmatically.

import { GetBucketLifecycleConfigurationCommand, NoSuchLifecycleConfiguration } from '@aws-sdk/client-s3';

async function addLifecycleRule(bucket: string, newRule: LifecycleRule) {
  let existingRules: LifecycleRule[] = [];

  try {
    const { Rules } = await s3.send(
      new GetBucketLifecycleConfigurationCommand({ Bucket: bucket })
    );
    existingRules = Rules ?? [];
  } catch (err: any) {
    // No lifecycle configuration yet — that's fine
    if (err.name !== 'NoSuchLifecycleConfiguration') throw err;
  }

  // Replace rule with same ID, or append
  const updatedRules = [
    ...existingRules.filter((r) => r.ID !== newRule.ID),
    newRule,
  ];

  await s3.send(
    new PutBucketLifecycleConfigurationCommand({
      Bucket: bucket,
      LifecycleConfiguration: { Rules: updatedRules },
    })
  );
}

Common errors and fixes

Error / IssueCauseFix
MalformedXML or InvalidArgumentRule missing required fields (ID, Status, Filter, at least one action)All rules require ID + Status + Filter; Filter can be empty {} for all objects but not omitted
Objects not expiring on scheduleLifecycle evaluation is async, runs nightlyExpect 1–2 day delay; not suitable for real-time cleanup
Standard-IA transition rejectedObjects smaller than 128 KB — S3 bills minimum 128 KB for IA classesAdd a size filter: Filter: { And: { Prefix: 'uploads/', ObjectSizeGreaterThan: 131072 } }
Transition rule conflictsTwo rules apply to the same object with conflicting transitionsS3 applies the most cost-effective transition; avoid overlapping filters to prevent confusion
Noncurrent versions not expiringUsing Expiration.Days (applies to current version) instead of NoncurrentVersionExpirationUse NoncurrentVersionExpiration.NoncurrentDays for versioned buckets
Orphaned delete markers accumulatingVersioned objects expired but delete markers remainAdd Expiration: { ExpiredObjectDeleteMarker: true } to same rule
Intelligent-Tiering costing more than StandardMonitoring fee on many small objects (< 128 KB)Add size filter ObjectSizeGreaterThan: 131072 to IT configuration

Related guides