Skip to content

Using Wildcard at S3 lifecycle rule

0

Hello

I want to apply S3 lifecycle to multiple prefixes

can I use wildcard at S3 lifecycle rule?

asked 2 years ago1.6K views

2 Answers
0
Accepted Answer

Hello,

Unfortunately, S3 cannot identify wildcard. S3 just treat '*' as normal character.

For example, if you apply s3 lifecycle rule to a prefix 'test-', S3 will be looing for prefix starts with 'test-' such as 'test-*a', 'test-*b'.

In this case, you can just apply 'test-' to the filter. This way s3 lifecycle will be applied to 'test-a', test-'b', etc.

Here's an AWS official document you can refer to: https://docs.aws.amazon.com/AmazonS3/latest/userguide/how-to-set-lifecycle-configuration-intro.html#how-to-set-lifecycle-configuration

AWS

answered 2 years ago

EXPERT

reviewed 2 years ago

0

Unfortunately, Amazon S3 Lifecycle rules do not support using wildcards or including multiple prefixes directly in a single rule. However, there are a couple of approaches you can consider to achieve a similar result:

  1. Use separate rules: If you want to apply lifecycle actions to objects with different key name prefixes, you can create separate rules for each prefix. For example, if you want to apply actions to objects with prefixes "projectA/" and "projectB/", you would create two distinct rules, each with its own prefix filter.

  2. Use a partial prefix: If your prefixes start with the same characters, you can include all of those prefixes in a single rule by specifying a partial prefix without a trailing slash. For instance, if you have prefixes like "sales1999/", "sales2000/", and "sales2001/", you could use "sales" as the prefix in your lifecycle rule to include all of these.

  3. Use object tags: Instead of relying on prefixes, you can use object tags to group objects that should be subject to the same lifecycle rule. This approach allows you to apply a single rule to objects across different prefixes as long as they share the same tag.

  4. Apply to all objects: If applicable, you can create a rule that applies to all objects in the bucket by not specifying a prefix filter.

While these methods don't use wildcards directly, they provide ways to manage lifecycle rules for multiple groups of objects within your S3 bucket. Choose the approach that best fits your specific use case and object organization strategy.
Sources
Troubleshooting Amazon S3 Lifecycle issues - Amazon Simple Storage Service
Lifecycle configuration elements - Amazon Simple Storage Service
Creating and managing a lifecycle rule by using the AWS Management Console - Amazon S3 on Outposts

answered 2 years ago

EXPERT

reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.