Amazon Partner

Tuesday, 21 March 2023

How to Create Directory or Folder in AWS S3 bucket

 In Amazon S3, there are no directories as such, only objects with keys that are structured like directory paths. You can create an object with a key that includes a directory path to simulate a directory. Here's how to create a simulated directory using the AWS Command Line Interface (CLI):

  1. Open your terminal or command prompt and make sure that you have installed and configured the AWS CLI.
  2. Type the following command to create a new S3 bucket:
    javascript
    aws s3 mb s3://your-bucket-name
  3. Type the following command to create a simulated directory within the bucket:
    css
    aws s3api put-object --bucket your-bucket-name --key your-folder-name/
    Note: Be sure to include the forward slash at the end of the key name to indicate that it is a directory and not a file.

After running these commands, you should see the new bucket and simulated directory in your S3 console. You can now upload files to this simulated directory by specifying the full key name, including the directory path. For example, to upload a file to the directory you just created, you can use the following command:

bash
aws s3 cp /path/to/local/file s3://your-bucket-name/your-folder-name/file-name

This will upload the file to the your-folder-name directory in your S3 bucket.

No comments:

Post a Comment