Search code examples
amazon-web-servicesamazon-s3cloudlifecycle

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.


Solution

  • 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.