Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
881 views
in Technique[技术] by (71.8m points)

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

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)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...