AWS S3 : Do Lifecycle rules accept regex? - amazon-web-services

I have an s3 bucket with "folders" folder1, folder2, folder3, folder4. In folder2 and folder3 there is a "new" folder. I need to delete everything in "new", older than 1 day. Can I do that with a rule like /*/new/ ? Some guys say they have seen such rules work in the past, but that particular definition does nothing.
(In the real bucket there are folder1, folder2 ... folder3001 so I can't make rules for every folder, so please don't suggest that. The above example is for simplicity only.)

The PUT livecycle API takes a "Prefix", which as the name says is a prefix, not a regex.
http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketPUTlifecycle.html
There is also a limit of 1000 rules per bucket.
http://docs.aws.amazon.com/AmazonS3/latest/dev/object-lifecycle-mgmt.html
You could change your folder structure so that keys look like "new/folderN".

Related

AWS configuration to delete files

I have a folder "Execution" folder in s3 bucket.
It has folders and files like
Execution
Exec_06-06-2022/
file1.json
file2.json
Exec_07-06-2022/
file3.json
file4.json
I need to configure to delete the Exec_datestamp folders and the inside files after X days.
I tried this using AWS lifecycle config for the prefix "Execution/"
But it deletes the folder Execution/ after X days ( set this to 1 day to test)
Is there any other way to achieve this?
There are no folders in S3. Execution is part of objects name, specifically its key prefix. The S3 console only makes Execution to appear as a folder, but there is no such thing in S3. So your lifecycle deletes Execution/ object (not folder), because it matches your query.
You can try with Execution/Exec* filter.
Got it, https://stackoverflow.com/a/41459761/5010582. The prefix has to be "Execution/Exec" without any wildcard.

AWS S3 Lifecycle

I've been exploring AWS S3 Lifecycle techniques and found the best way to delete S3 files > 60 days old is to configure this through the GUI.
However, I'm not wanting to delete ALL files greater than 60 days. For example, I'd like to at least keep all HTML files inside the bucket that are greater than 60 days.
I've found that a prefix can be entered to limit the scope of the lifecycle to a specific file; however, this requires me to enter ALL files EXCEPT HTMLs. We have hundreds of files, so this will take forever.
I was wondering if anyone knew of an easier way? For example, I would like to just exclude all *.html from the lifecycle.
There is no way to exclude object from rules.
You can rearrange object in your bucket so rule can be applied to objects in specified prefix ("folder").

Amazon S3 - Can prefixes include the start of the file name?

I have several types of files within an Amazon S3 bucket, all of which are in the same folder. There are three "types" of files that I wan't to apply different transition/delete days to, and all of their filenames start the same way. I am wondering if prefixes for files need to just address folders, or if they can include the start of the filename as well. For example, the files start with data_file_*, log_file_*, and error_file_*, if they are all in a folder files/, can I set a rule with the prefix being files/error_file_? If so, is that syntax correct?
Note that changing the directory structure is not an option for me, and the AWS documentation doesn't have any examples like this, or any related comments that I can find.
The use-case you describe is actually the only valid way to set lifecycle rules. S3 has no concept of "folders" (even though it looks like that in the AWS console). It only understands filenames that happen to have slashes in them. This is typical for object based store (S3), in contrast to file storage (your laptop).
So when creating lifecycle rules, include the full path of the object (files/error_file_). Then the rule will be applied to all files with that prefix.

Rename parent folder in S3

We know that in S3 objects, the folder path is just a part of the object key itself.
Having an object structure similar to the following:
/files/user/09874/01/
/files/user/09875/01/
/files/user/09875/02/
/files/user/09876/01/
/files/user/09876/02/
What kind of operation would you recommend to rename the parent /files/ to /something/, having in mind that there are thousands of files and that the number of requests should be the cheapest/minimum?
(with the following docs under consideration)
As you said prefix are part of the file name. Unfortunately, The only way that i can think of is to iterate the list of objects and move to the new prefix.
in cli:
aws s3 mv --recursive s3://bucket/files s3://bucket/something/

Does Amazon S3 have folders?

This documentation says that quote:
create a bucket with folders
IIUC S3 does not have folders. We can simulate folders by including the folder name in the object key like this:
folder1/key1.json
folder1/key2.json
Is my understanding correct?
you are correct - there are no real folders, they are just simulated based on the object key having the slash in its name.