Creating folders and subfolders in an S3 bucket using Lambda Functions

Does anybody know how to create folders and subfolders in an S3 bucket using Lambda Functions? Thanks. Preferably in JS?

This is a classic misunderstanding. S3 is not a filesystem so it has no concept of folders / directories.

For convenience if you create a key with the / character it will be presented like a “folder” hierarchy in the Console. So if you wanted to create the “folder” my_stuff with the objects a.txt and b.txt in it you would put two objects to S3 with the following keys:
Note there is no way to delete the “folder” my_stuffwhen all objects with that subkey are removed the folder will be gone.

If you wanted it to make it look like there was an empty folder in the console you could create the empty object called my_stuff/ (note the forward slash)

Some examples of using the JS SDK with S3 here

I prefer to think of S3 like a [very large scale] key/value store than a file system. Personal preference maybe, but I’ve heard of other people having success thinking of it that way too.