<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1063935717132479&amp;ev=PageView&amp;noscript=1 https://www.facebook.com/tr?id=1063935717132479&amp;ev=PageView&amp;noscript=1 "> Object Expirations

Object Expirations

An expiration (or lifecycle rule) tells the bucket to automatically delete or move an object after a set amount of time. You configure it once, and the storage service enforces it. This is housekeeping on autopilot. Old files clean themselves up so you don't have to remember.

day 0 tmp/report.csv created day 7 auto-deleted by the bucket
You configure the lifecycle rule once. The storage service deletes objects under tmp/ seven days after they're created, with no cleanup code from you.

How to use it

import { PutBucketLifecycleConfigurationCommand } from "@aws-sdk/client-s3";

// Tell the bucket to delete anything under "tmp/" 7 days after it's created
await s3.send(new PutBucketLifecycleConfigurationCommand({
  Bucket: "my-app-uploads",
  LifecycleConfiguration: {
    Rules: [
      {
        ID: "expire-tmp",
        Filter: { Prefix: "tmp/" },
        Expiration: { Days: 7 },
        Status: "Enabled",
      },
    ],
  },
}));

You set this once per bucket; the storage service enforces it from then on.

Exercise

Node challenge · runs in your browser