How to list all files in S3 bucket with AWS CLI?

How to list all files in S3 bucket with AWS CLI?

Want to list all the files in the s3 bucket using AWS CLI? working with CLIs makes you look like a hacker.

Before we get started

To work with AWS CLI, we need to install the CLI first on our machine.

You can install CLI on windows, macOS, and Linux.

I will show you on windows for the macOS and Linux. Follow the below link.

CLI installation link for mac and Linux

Installing CLI on Windows

For Windows users, an MSI installer is available on AWS CLI GitHub. You can download it from there.

Step 1: Click on the below link to download the AWS CLI version 2.

Download link for AWS CLI V2

Or, you can download it by pasting the below command inside your windows Powershell.

msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msiCode language: Shell Session (shell)

Once you download using any of those two ways. 

If you have downloaded it by clicking on the above link, then open the MSI installer by double clicking on it, the interface should look like this.

If you have pasted that `msiexec` command into your PowerShell command, you do not need to do anything. It will download the CLI and open the installer.

AWS CLI Installer
AWS CLI Installer

Step 2: Click on next, and accept the terms and conditions. And then again, click on the next button a few times till you see the install button.

Step 3: Click on Install. The CLI installer will take a few minutes to install, and then you will see the finish button, click on the finish button to close the installer.

Confirm Installation

To verify you have installed the AWS CLI correctly, run the below command inside your terminal.

aws --versionCode language: Shell Session (shell)

You should see the below image. Else you need to install it again.

CLI Version
CLI Version

We need to do only one thing before we use the CLI, and we need to configure it.

Open the command prompt and paste the below code inside your terminal.

aws configureCode language: Shell Session (shell)

It will ask you for access key ID, Key Secrets, Region, and Output Format.

Once done, we are ready to list the files from the bucket.

Resource URL for was configure

List all the Files in an S3 Bucket using AWS CLI

Step 1: First, sign in to your account.

Step 2: Inside the search bar, search for the s3 service. Alternatively, you can press ALT + S to go to the search bar.

Step 3: Click on the S3. If you don’t have buckets, it will ask you to create a bucket first. If you have a bucket, follow step 4.

Follow the step below if you don’t have a bucket,

Click on the create bucket, give the bucket name, select your bucket location, and leave the rest of things as default. 

Make sure your bucket name should be unique. Once you have filled everything, click on the create bucket button.

Step 4: Paste the below the code inside your command terminal,

aws s3 ls s3://bucketname --recursive --human-readable --summarizeCode language: Shell Session (shell)

Replace the bucket name with your bucket name, which will list all the files from your s3 bucket.

If you want to list the folders from the bucket, copy the below code and paste it inside your terminal. Make sure to change the bucket name with your bucket name.

aws s3 ls s3://YOUR_BUCKET/YOUR_FOLDER/ <mdspan datatext="el1664819055385" class="mdspan-comment">--</mdspan>recursive --human-readable --summarizeCode language: Shell Session (shell)

Troubleshoot Resources

If you found difficulty following this tutorial, below, I have listed the resources that will possibly fix the errors you face.

Blocking public Access to your s3 bucket

Summary

I hope now you know how to list the files and folders from your s3 bucket. If you found this article helpful, bookmark it. 

Thanks for reading ?.

Sharing is caring

Did you like what Mujahid Khan H A wrote? Thank them for their work by sharing it on social media.

0/10000

No comments so far