Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does amazons3.listObjects(bucket,prefix) accept regex as a prefix to find objects?

Can I use regex as a prefix in listobjects from amazons3 in Java aws sdk

like image 334
Mynyy Avatar asked Nov 16 '25 09:11

Mynyy


1 Answers

As commenter @luk2302 already said, it is not possible.

The fact that you are trying to solve your problem with regex points to an interesting and often underestimated issue:

How to effectively model your data in S3.

S3 is commonly thought of as just a "disk in the cloud". But it is more like a database. Usually, we design our data in databases with relations etc. and use indexes. We create a data model based on the data we have and the way we want to access it.

You can do the same in S3.

You could think of the prefix as a kind of index. Everything that belongs together and you want to have fast access to should have the same prefix.

For example:

Imagine your application stores images. Furthermore, imagine you went on a nice vacation in France in 2019.

You could structure it like this (in terms of prefixes):

/images/2019_france

Now you would need to use a "regex" if you want all pictures taken in France :

/images/*_france

And as we know, that does not work. So if you find yourself often looking for pictures taken in a specific country, you probably should structure your data in S3 like this:

/images/france/2019

Now it is easy to find all the pictures taken in france by using the prefix:

/images/france

If you more often look for pictures by year, then maybe you need to structure your bucket like this:

/images/2019

I hope the point is clear:

Prefix design is important when working with S3.

like image 103
Jens Avatar answered Nov 19 '25 00:11

Jens



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!