A "key" in S3 is similar to a file path:
http://bucket.s3.amazonaws.com/some/path/to/use
... is in a bucket named bucket
and has a key of some/path/to/use
.
It's not actually a path though, because there are no folders. The S3 key is just the file name for a file in one big directory (the entire bucket). S3 keys can contain /
, but it has no special meaning unless you set the delimiter
argument with listing a bucket.
In other words, having an object named some/object
doesn't tell you anything about the object some
(it might or might not exist -- the two objects are not related).
However, you can request keys with a specific prefix, so I could say "give me all keys starting with some/path/to/
and it will return some/path/to/use
. It looks like "listing a directory", but it's really just asking for files that start with a specific string of characters.
I could just as easily name things like this:
somepathtousea
somepathtouseb
And say "give me everything starting with somepathtouse
" (and it would say somepathtousea
and somepathtouseb
).
Note: S3 URL's come in several forms:
http://s3.amazonaws.com/bucket/key
http://bucket.s3.amazonaws.com/key
http://bucket/key (where bucket is a DNS CNAME record pointing to bucket.s3.amazonaws.com)
EDIT:
I looked at the JavaDocs and this is the function signature I see (for AmazonS3Client
):
public void deleteObject(java.lang.String bucketName,
java.lang.String key)
throws AmazonClientException,
AmazonServiceException
EDIT again:
Folders do kind-of exist now, as zero-length objects with a content-type of application/x-directory
and a key ending in /
:
$ AWS_PROFILE=prod aws s3api head-object --bucket example-bucket --key example-directory/
{
"AcceptRanges": "bytes",
"LastModified": "Mon, 29 Apr 2019 14:59:36 GMT",
"ContentLength": 0,
"ETag": "\"d41d8cd98f00b204e9800998ecf8427e\"",
"ContentType": "application/x-directory",
"ServerSideEncryption": "AES256",
"Metadata": {}
}
This is still just convention and there's nothing stopping you from having files ending /
or files inside of "folders" that don't exist.