Search code examples
pythonpython-3.xamazon-s3s3-bucket

Is there any way to create a folder in the already existing S3 bucket thorugh python?


In the documentation of boto3 there is no function to do make a directory in the bucket. Although we can add the folder manually but I need some code to do through python.


Solution

  • You do not need to create folders in S3.

    If you create an object with the key pics/cats/funny.gif, the "folder" cats will automatically appear inside the "folder" pics.

    The word "folder" is in quotes because folders are not containers in S3. They are derived for display from the / delimiters in the object keys.

    If you want to see empty folders, you can create empty objects (containing 0 bytes, an empty string) with names ending in / such as pics/ or pics/cats/ but these serve no real purpose other than allowing you to see them in the console while they are "empty."

    S3 technically stores your objects in a flat lexical index space, not in a hierarchy. The console will organize objects with / in their names into visible folders, automatically.

    This is explained in Working with Folders.