Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security & DevOps Insights

  • Home
  • About
  • Advertise With US
  • Reviews
  • Contact
  • Toggle search form
Home » Linux » How to delete AWS S3 Bucket and Objects via  AWS CLI from Linux
  • ArchiveUnarchiveDelete134
    Manage a GitLab Project: How to archive or unarchive and delete GitLab projects Version Control System
  • How to use Netstat.exe to confirm which Program uses or blocks a port
    How to use Netstat.exe to confirm which Program uses or blocks a port Linux
  • dev
    Disable Developer Tools in Microsoft Edge using Registry or Group Policy in Windows Windows
  • Trellix Invalid credential
    Fix unable to login to Trellix ePO with Windows authentication Windows Server
  • Fatal Refusing to Merge
    How to Fix Fatal Git Error Refusing to Merge Unrelated Histories Version Control System
  • feature image
    How to install PostgreSQL on Ubuntu Linux
  • ClearTPM
    Clear TPM via Management Console or Windows Defender Center App Windows
  • DeleteAzureVM
    Remove Azure VM: How to delete a Virtual Machine via the Azure Portal AWS/Azure/OpenShift

How to delete AWS S3 Bucket and Objects via  AWS CLI from Linux

Posted on 19/01/202317/03/2023 Imoh Etuk By Imoh Etuk No Comments on How to delete AWS S3 Bucket and Objects via  AWS CLI from Linux
S3-Bucket-1
S3 Buckets

The Amazon Simple Storage Service (Amazon S3) is a cloud hosting service that offers industry-leading performance, security, and scalability. Users and organizations of all sizes can use Amazon S3 to safeguard and store data for a variety of applications, including websites, mobile applications, data lakes, backups and restores, archives, enterprise applications, IoT devices, and big data analytics. Amazon S3 can be used to optimize, organize, and configure access to your data based on your specific business, organizational, and compliance requirements. In this guide, you will learn how to delete AWS S3 Bucket and Objects via  AWS CLI from Linux.

To learn how to interact with the AWS S3 bucket using AWS CLI on Windows, refer to How to Programmatically Assess AWS Management Console and Create Resources from the Command-line using AWS CLI in Windows, Understanding AWS CLI: How to configure Command Line Interface [Part 2], How to add an EBS volume to AWS EC2 via the AWS Console and CLI

Amazon S3 is an object cloud storage service that stores data in buckets as objects. A file and any metadata that describes the file are considered objects. AWS S3 bucket is a container that holds objects. A bucket is a storage location for items in Amazon S3. A bucket can hold any number of items, and your account can hold up to 100 buckets.

Delete AWS S3 Bucket and Objects via  AWS CLI from Linux

In order to fulfil this goal of this topic, we will have to define the core concept of the management tool we will be using for this task.

AWS Command Line Interface (AWS CLI)

The AWS Command Line Interface (AWS CLI) is a centralized management tool for your AWS services. You can control multiple AWS services from the command line and automate them using scripts with just one tool to install and set up. It is a free and open-source tool for interacting with AWS services via command-line shell commands.

With minimal configuration, the AWS CLI allows you to start running commands that use functionality similar to that of the browser-based AWS Management Console from the command prompt in your terminal program.

In this post, I will take you through the following: installing the AWS CLI package on a local system, assigning permissions to the user, generating and configuring the access key ID and secret access key, and deleting the S3 bucket and its objects using the AWS CLI. We will carry out all the interactions with the AWS S3 bucket directly from the Linux terminal.

Prerequisite for Installing AWS CLI

To follow along in this write-up, you need to have the following:

  1. Install AWS CLI on your PC, see a related guide  AWS Command-Line Interface: How to configure AWS CLI [Part 1] 
  2. Active AWS Subscription
  3. Have the IAM Permission to create and manage S3 Bucket

Installing AWS CLI package on a local system

To install the AWS CLI package on your system, run the below commands to update your system packages and then download the AWS CLI.

sudo apt update -y
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
Install-AWS-CLI
Downloading AWS CLI

After downloading the awsscli, run the sudo apt install unzip and unzip awscliv2.zip to you to install unzip and use it to unzip the file.

Install-Unzip-command-
Installing Unzip package and unzipping the awscli file

Now, install the awscli by running:

sudo ./aws/install

Please note the directory where you unzip the file to. Here the file was extracted to the AWS folder.

Install-CLI
Installing AWS CLI

Assign permissions to the user

AWS offers IAM roles and policies to limit user access to various AWS resources. Your user account must have specific permissions before performing any action on AWS. This section will grant the user account the necessary permissions to perform various tasks on S3. To begin, log in to the AWS management console and navigate to the IAM service.

Creating-an-IAM-User
Accessing IAM Portal

While on the Identity and Access Management (IAM) portal, click on User

Adding-an-IAM-User
Adding a User

Specify the username

Specify-the-user-name

Add User to a Group

Add-user-to-group
Adding a User to a group

Assign permission to the user to be able to manage S3 Bucket by clicking on the Add inline policy

Assign-permission
Assigning permission to the User

Search for and select S3 from the list of services

S3-Bucket-2
Attaching the appropriate permissions

Generating and configuring the access key ID and secret access key

You need some credentials to authorize your requests in order to use the AWS command-line interface on your local computer. AWS access key ID and secret access key are used as credentials for the AWS command-line interface. We will create and set up these credentials on our local system in this section.

To generate and configure the access key ID and secret access key, go to the Users section of the IAM console, then click on the username.

Clicking-on-the-user-name
Assessing the User

Click the Create access key button after scrolling down to the Access keys section.

Click-on-Create-access-key
Creating Access Key

Choose how you want to use the Access key

Choose-access-key-best-practices
Choosing the best practice for your access key

Download the CSV file containing the access key ID and secret access Key

Retrieve-the-access-key
Download the Acces key

Use the terminal on your local system to configure the AWS command-line credentials after they have been generated and downloaded. To configure the credentials, use the aws configure command and supply the access key ID and secret access key, set your default region, and default output format.

AWS-Configure-Access-Key
Configuring the AWS Access Key ID and Secret Access Key

We have two buckets on our account.

List S3 Bucket Objects with CLI

Let’s list the objects/files in one of the S3 bucket using the below command:

aws s3 ls <bucket-name>
List-bucket-objects
Listing S3 Bucket Objects

There are about six objects in one of the buckets.

Deleting S3 Bucket Object using AWS CLI

To empty all the objects in your S3 Buckets, run:

aws s3 rm s3://<bucket-name> --recursive
Deleting-S3-bucket-objects
Deleting S3 Bucket Objects

Verify that the objects have been deleted by running:

aws s3 ls <bucket-name>
Verify-the-objects-have-been-deleted
Verifying deleted S3 Bucket Objects

Deleting S3 Bucket

Now that we have emptied the S3 Bucket, let’s proceed to delete the entire bucket using the below command:

aws s3 r s3://<bucket-name>
Removing-bucket
Deleting S3 Bucket

Congratulations! You have learned how to delete AWS S3 Bucket and Objects via  AWS CLI from Linux. In conclusion, AWS CLI is a powerful tool that you can use to centrally control and manage your resources in your AWS environment.

In summary, we discussed how to install and configure the AWS CLI package in your Local PC’s terminal and directly interacted with AWS S3 buckets and their objects. You also got to understand how to create an IAM User and assign permission to them and finally learnt how to delete S3 bucket objects and the entire S3 bucket.

Rate this post

Thank you for reading this post. Kindly share it with others.

  • Share on X (Opens in new window) X
  • Share on Reddit (Opens in new window) Reddit
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Facebook (Opens in new window) Facebook
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Telegram (Opens in new window) Telegram
  • Share on WhatsApp (Opens in new window) WhatsApp
  • Share on Pocket (Opens in new window) Pocket
  • Share on Mastodon (Opens in new window) Mastodon
  • Share on Bluesky (Opens in new window) Bluesky
  • Share on Threads (Opens in new window) Threads
  • Share on Nextdoor (Opens in new window) Nextdoor
AWS/Azure/OpenShift, Linux Tags:AWS, AWS CLI, S3 Bucket

Post navigation

Previous Post: Install Ubuntu 20.04 LTS on Windows via WSL
Next Post: Enable BitLocker AES-XTX 256 Encryption

Related Posts

  • PersonalHow to Create Symbolic Links in Linux
    All You Need to Know About Symbolic Links in Linux Linux
  • Webp.net resizeimage 1
    Automate Infrastructure Deployments in the Cloud with Ansible and Azure Pipelines AWS/Azure/OpenShift
  • image 166
    How to deploy a .NET application to AWS Elastic Beanstalk using AWS Tool Kit AWS/Azure/OpenShift
  • Amazon EC2 and S3
    How to sync S3 Bucket with an EC2 instance AWS/Azure/OpenShift
  • FEATURE IMAGE
    SSH into a VM created using Azure CLI or GUI Linux
  • Slide1
    Read-only Files: Saving Files in VIM Editor on Linux/Unix-like OS Linux

More Related Articles

PersonalHow to Create Symbolic Links in Linux All You Need to Know About Symbolic Links in Linux Linux
Webp.net resizeimage 1 Automate Infrastructure Deployments in the Cloud with Ansible and Azure Pipelines AWS/Azure/OpenShift
image 166 How to deploy a .NET application to AWS Elastic Beanstalk using AWS Tool Kit AWS/Azure/OpenShift
Amazon EC2 and S3 How to sync S3 Bucket with an EC2 instance AWS/Azure/OpenShift
FEATURE IMAGE SSH into a VM created using Azure CLI or GUI Linux
Slide1 Read-only Files: Saving Files in VIM Editor on Linux/Unix-like OS Linux

Leave a Reply Cancel reply

You must be logged in to post a comment.

Microsoft MVP

VEEAMLEGEND

vexpert-badge-stars-5

Virtual Background

GoogleNews

Categories

veeaam100

sysadmin top30a

  • ArchiveUnarchiveDelete134
    Manage a GitLab Project: How to archive or unarchive and delete GitLab projects Version Control System
  • How to use Netstat.exe to confirm which Program uses or blocks a port
    How to use Netstat.exe to confirm which Program uses or blocks a port Linux
  • dev
    Disable Developer Tools in Microsoft Edge using Registry or Group Policy in Windows Windows
  • Trellix Invalid credential
    Fix unable to login to Trellix ePO with Windows authentication Windows Server
  • Fatal Refusing to Merge
    How to Fix Fatal Git Error Refusing to Merge Unrelated Histories Version Control System
  • feature image
    How to install PostgreSQL on Ubuntu Linux
  • ClearTPM
    Clear TPM via Management Console or Windows Defender Center App Windows
  • DeleteAzureVM
    Remove Azure VM: How to delete a Virtual Machine via the Azure Portal AWS/Azure/OpenShift

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,834 other subscribers
  • RSS - Posts
  • RSS - Comments
  • About
  • Authors
  • Write for us
  • Advertise with us
  • General Terms and Conditions
  • Privacy policy
  • Feedly
  • Telegram
  • Youtube
  • Facebook
  • Instagram
  • LinkedIn
  • Tumblr
  • Pinterest
  • Twitter
  • mastodon

Tags

Active Directory AWS Azure Bitlocker Microsoft Windows PowerShell WDS Windows 10 Windows 11 Windows Server 2016

Copyright © 2025 TechDirectArchive

 

Loading Comments...
 

You must be logged in to post a comment.