0

How to access a folder object inside S3 bucket. How can I access a folder inside S3 bucket using python boto3. Code is working for a folder in S3 bucket but to for folders inside S3 bucket

3
  • Could you please clarify what you are trying to achieve? For what purpose do you wish to "access a folder"? What are you doing that is failing to work? Commented Oct 14, 2018 at 20:22
  • And please share code you have tried. Commented Oct 14, 2018 at 21:12
  • It creates a json file every time lambda function runs. I want to store that json file inside a folder in S3 bucket. My S3 bucket name is "bucketstore"...folder inside bucket is "jsonstore", I tried "bucketstore/jsonstore" it's showing invalid bucket name Commented Oct 15, 2018 at 4:03

3 Answers 3

2

Little principle info: S3 does not have folders, it is object store. The folder like structure which you see in the UI is for convenience.

For the upload see here

Sign up to request clarification or add additional context in comments.

Comments

2

If I understand you correctly.. I had this issue in my python3 script. Basically you need to pass the to the boto3 function an s3 bucket and the file name. Make this file name include the folder, with the forward slash separating them. Instead of passing just the file name and trying to pass the folder as a separate parameter.

So if you have MyS3Bucket and you want to upload file.txt to MyFolder inside MyS3Bucket, then pass the file_name=“MyFolder”+”/“+”file.txt” as a parameter to the upload function. Let me know if you need a code snippet.

Even if you don’t have the folder in the S3 bucket, boto3 will create it for you on the fly. This is cool because you can grant access in s3 based on a folder, not just the whole bucket at once.

Good luck!

Comments

0

If I wanted to upload the following directory:

folder_root
├── a
│   └── f
├── b
│   ├── d
│   └── e
└── c
    └── x

You will want to upload individual files called a/f, b/d, b/e, and c/x. As the other answer states, there is no concept of a directory within S3, it is a "flat object store". If you want to create the appearance of directories, the names (or keys) of the files must be the directory structure you're trying to create.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.