Uploading Files to an S3 Bucket using AWS CLI

José Manuel Gilpérez
2 min readJun 17, 2023

In this tutorial, we will explore the process of uploading files to an S3 bucket using the AWS Command Line Interface (CLI). We will cover the creation of an S3 bucket, uploading files from the S3 console, installing the AWS CLI, obtaining necessary credentials, and performing file uploads using the CLI.

Prerequisites:

  • An AWS account
  • AWS CLI installed on your machine

Steps:

1. Create a new S3 Bucket:

  1. Sign in to your AWS Management Console.
  2. Navigate to the S3 service.
  3. Click on “Create bucket” and provide a unique name for your bucket.
  4. Select the desired region and configure other options as needed.
  5. Set the appropriate permissions for your bucket.
  6. Review the configuration and create the bucket.

2. Upload Files from the S3 Console:

  1. Open the S3 console.
  2. Select the desired bucket.
  3. Click on the “Upload” button.
  4. Add the files or folder you want to upload.
  5. Configure additional settings if required.
  6. Start the upload process.
  7. Monitor the upload progress in the console.
  8. Once the upload is complete, the files will be available in the bucket.

3. Install AWS CLI:

  1. Open your Terminal application.
  2. Install AWS CLI using Homebrew with the command: brew install awscli.
  3. Verify the installation with aws --version.
  4. Configure AWS credentials using aws configure if not done already.

4. Upload Files to the S3 Bucket:

To upload files using the AWS CLI, execute the following command:

aws s3 cp /path/to/source s3://bucket-name/ --recursive

Replace /path/to/source with the local directory or file you want to upload, and bucket-name with the name of your S3 bucket. The --recursive flag ensures all files and subdirectories are uploaded.

5. Retrieve a List of Files in the S3 Bucket:

To obtain a list of files in an S3 bucket, you can use the following command:

aws s3api list-objects --bucket bucket-name --query 'Contents[].Key' --output text > output-file.txt

Replace bucket-name with the name of your S3 bucket. This command will save the list of file names to a text file called output-file.txt in your local machine's current directory.

Conclusion: Using the AWS CLI, you can easily upload files to an S3 bucket in a batch or individual manner. The CLI provides flexibility and automation, making the process efficient and manageable. By following the steps outlined in this tutorial, you can effectively upload files to your S3 bucket and retrieve a list of file names for further analysis or reference.

Remember to ensure proper permissions and credentials are set up to access your S3 bucket through the AWS CLI.

--

--