2

How can I create a bucket inside a bucket using the aws cli? When I use the "mb" command it states that I already own it (but I don't). The top level bucket "example-bucket" already exists. I need to know how to create the "testing" bucket using the cli.

[ec2-user@ip-10-0-0-0 ~]$ aws s3 mb s3://example-bucket/testing --region us-west-2
make_bucket failed: s3://example-bucket/testing An error occurred (BucketAlreadyOwnedByYou) when calling the CreateBucket operation: Your previous request to create the named bucket succeeded and you already own it.

3 Answers 3

3

This is not possible. As the documentation states:

You cannot create a bucket within another bucket.

1

Buckets are the highest level container in AWS S3. You can't have a bucket inside a bucket - it doesn't make sense given how the service works.

S3 is an object store, not a file system, and it doesn't have folders as such. You can create objects with a path separator, when you view the bucket in the web console it shows it with a folder / tree view. You don't need to create the "folder" in advance, simply putting an object with the correct key will do this. There's a good guide to S3 folders here.

An AWS CLI command like this will put an object into S3 within what looks like a folder. An API call will be similar

aws s3 cp filename.txt s3://bucketname/folder/filename.txt

The AWS S3 documentation is quite good. The AWS S3 CLI cp command is documented here.

0

Apparently you can't us "aws s3 mb". I had to use "aws s3api put-object"

aws s3api put-object --bucket example-bucket --key testing/

The forward slash is needed so that aws knows it is a directory otherwise it will create an empty file.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .