Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify an object expiration prefix that doesn't match the directory?

Tags:

amazon-s3

I have an S3 bucket with img, mov, and tmp directories. I would like everything added to tmp to be removed automatically once it's over three days old. So I set up object expiration rules on my bucket like so:

  • prefix: "tmp/"
  • expiration: 3

The problem is, while the files inside tmp are removed on schedule, tmp itself also matches this prefix (dispite the trailing slash) and gets deleted every three days.

Is there any prefix that will match the contents of tmp, but not tmp itself? Something like "tmp/*" (though that doesn't work)?

like image 769
jemmons Avatar asked Feb 23 '12 22:02

jemmons


Video Answer


1 Answers

Why do you want to keep tmp at all?

Amazon S3 doesn't actually have a native concept of folders/directories, rather is a flat storage architecture comprised of buckets and objects/keys only - the directory style presentation seen in most tools for S3 (including the AWS Management Console itself) is based solely on convention, i.e. simulating a hierarchy for objects with identical prefixes (e.g.tmp/ in your case); see the respective FAQ How is Amazon S3 data organized?:

Amazon S3 is a simple key-based object store. When you store data, you assign a unique object key that can later be used to retrieve the data. Keys can be any string, and can be constructed to mimic hierarchical attributes.

[emphasis mine]

This architecture is further detailed in Amazon S3 Concepts:

Buckets

A bucket is a container for objects stored in Amazon S3. Every object is contained in a bucket. For example, if the object named photos/puppy.jpg is stored in the johnsmith bucket, then it is addressable using the URL http://johnsmith.s3.amazonaws.com/photos/puppy.jpg

[...]

Keys

A key is the unique identifier for an object within a bucket. Every object in a bucket has exactly one key. Because the combination of a bucket, key, and version ID uniquely identify each object, Amazon S3 can be thought of as a basic data map between "bucket + key + version" and the object itself.

[emphasis mine]

Therefore there shouldn't be any need to care about these 'directories' at all, they will just resurface any time you happen to store an object with a respective prefix in its name.

like image 86
Steffen Opel Avatar answered Sep 28 '22 06:09

Steffen Opel