如何指定与目录不匹配的对象过期前缀? [英] How to specify an object expiration prefix that doesn't match the directory?

查看:21
本文介绍了如何指定与目录不匹配的对象过期前缀?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 imgmovtmp 目录的 S3 存储桶.我希望添加到 tmp 的所有内容在超过三天后自动删除.所以我在我的存储桶上设置了对象过期规则,如下所示:>

  • 前缀:tmp/"
  • 有效期:3

问题是,虽然 tmp 中的文件被按计划删除,tmp 本身也匹配这个前缀(不考虑尾部斜杠)并且每三天被删除一次.

是否有任何前缀可以匹配 tmp 的内容,但不匹配 tmp 本身?像tmp/*"这样的东西(虽然这不起作用)?

解决方案

你为什么要保留 tmp ?

Amazon S3 实际上没有文件夹/目录的原生概念,而是一个平面仅由存储桶和对象/键组成的存储架构 - 大多数 S3 工具(包括 AWS ManagementConsole 本身)完全基于约定,即模拟具有相同前缀的对象的层次结构(例如 tmp/ 在您的情况下);请参阅相应的常见问题解答 Amazon S3 数据是如何组织的?:

<块引用>

Amazon S3 是一个简单的基于键的对象存储.当您存储数据时,您分配一个唯一的对象键,以后可以用来检索数据.键可以是任何字符串,并且可以构造 来模仿分层属性.

[强调我的]

Amazon S3 概念中进一步详细介绍了此架构:

<块引用>

存储桶

存储桶是存储在 Amazon S3 中的对象的容器.每一个对象包含在一个桶中.例如,如果对象 命名为photos/puppy.jpg 存放在 johnsmith 桶中,那么就是可使用 URL 寻址http://johnsmith.s3.amazonaws.com/photos/puppy.jpg

[...]

键是存储桶中对象的唯一标识符.每个桶中的对象只有一个键.因为组合了一个存储桶、密钥和版本 ID 唯一标识每个对象,Amazon S3可以认为是bucket + key + version"之间的基本数据映射和对象本身.

[强调我的]

因此根本不需要关心这些目录",只要您碰巧存储名称中带有相应前缀的对象,它们就会重新出现.

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

解决方案

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.

这篇关于如何指定与目录不匹配的对象过期前缀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆