The Wayback Machine - https://web.archive.org/web/20240826230321/https://www.geeksforgeeks.org/how-to-aceses-aws-s3-bucket-using-aws-cli/
Open In App

How To Aceses AWS S3 Bucket Using AWS CLI ?

Last Updated : 05 Feb, 2024
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The AWS Command Line Interface (AWS CLI) is an open-source tool that allows you to interact with AWS services using syntax in your shell. It provides you with the ability to quickly and easily access the same functionality as the browser-based AWS Management Console from the comfort of your terminal program.

S3 (Simple Storage Service) is a storage service provided by AWS to store any kind of data in File/Folder format. In this article, we will see how easily we can access S3 to store our data in buckets which are containers to store your data.

Prerequisites

  • AWS Account: Before starting this tutorial, you must have an AWS account. Read this article in case you don’t have an AWS account.
  • AWS CLI: You should have AWS CLI set in your local machine with access. Refer to this article if you want to know how to set up AWS CLI.

Step-By-Step Guide To TO Aceses S3 Bucket Using AWS CLI

Step 1: Login into AWS -> https://aws.amazon.com/ Management

Step 2: After signing in you will land on the AWS Management Console page and search for S3 as shown below.

AWS Management Console

Step 3: From the sidebar go to buckets. A bucket is a container to store the objects (Files and Folders).

S3

Step 4: On the buckets page all of your buckets will be listed.

Buckets

To Create A New S3 Bucket

Step 5: Open Command Prompt/Powershell/Terminal on your system. Type the following command to make an S3 bucket.

Syntax :

aws s3 mb s3://bucket-name 

Make sure the bucket name is between 3 and 63 characters long and must contain only lower-case characters, numbers, periods, and dashes.Also, your bucket name should be unique as they are global in AWS.‘mb’ stands for make bucket in syntax.

Make bucket

Step 6: Goto AWS Management Console and refresh the buckets page, after refreshing you will be able to see your bucket name.

Bucket

To Copy A Single File To An S3 Bucket

Step 7: Let’s add some files in your bucket.

Syntax :

aws s3 cp 'your local file path' s3://bucket-name

‘cp’ stands for copy in syntax.‘bucket-name’ can also be your path, adding ‘/’ in front of the name will go to subfolders in the bucket. The above syntax will allow you to add a single file (not a folder) from the local computer to the S3 bucket.

Copy

To List all S3 buckets and all files present in the S3 bucket

Step 8: To check how many buckets are present in S3 use the following syntax

Syntax :

aws s3 ls

List bucket

Step 9: To check how many files are present in the S3 bucket use the following syntax

Syntax :

aws s3 ls bucket-name

List files

Step 10: Again, go to the AWS Managment Console refresh the buckets page and click on your bucket name to open the bucket. You will be able to see all the files present in your bucket which you copied from local machine.

File in bucket

To Copy Multiple Files/Folders To A S3 Bucket

Step 11: To add multiple files/folders in your bucket just add ‘–recursive‘ at the end of the single copy syntax. This will upload all the files from the given path.

Syntax :

aws s3 cp 'your local file path' s3://bucket-name --recursive

Multiple Files upload

Step 12: Again, go to AWS Managment Console and open your bucket. You will be able to see all the files present in your bucket that you copied from a local machine.You can also check files by listing them in terminal.

Upload files

Delete All Files/Folders From Bucket

Step 13: To delete objects from bucket just add path to bucket to delete everything inside bucket or add specific file/folder name to delete certain object.

Syntax:

aws s3 rm s3://path-to-file-folder

Example: aws s3 rm s3://gfg-s3-test-bucket -–recursive

To delete single file don’t add the ‘–recursive’ command.

Delete

Step 14: Open your bucket in the AWS Management Console, and check if file that you deleted is present or not. You can also use ‘list’ command to check it.

Empty bucket

Delete Bucket

Step 15: To delete the bucket just just add bucket name in front of the ‘rb’ command.

Syntax :

aws s3 rb s3://bucket-name

‘rb’ stands for remove bucket in the syntax.

Remove bucket

Step 16: Check on AWS Management Console. It will bucket ‘bucket-name’ was not found. You can also use ‘list’ command to check it.

Delete massage

Conclusion

In this article, we explored AWS CLI commands to perform various operations such as create, copy delete and list in the AWS S3 bucket. CLI makes it easy to perform tasks using simple commands and arguments.

S3 Bucket -FAQs

What credentials do I need to access an S3 bucket with AWS CLI?

It requires Access Key ID and Secret Access Key, which you can obtain from the AWS Management Console.

Can I access a specific S3 bucket using AWS CLI without configuring it globally?

Yes, you can use the –profile option while creating S3 bucket.

What is the syntax for downloading files from an S3 bucket using AWS CLI?

‘aws s3 cp object-url’ command can be also use to dowload the S3 object by just adding URL of the object.

Is it possible to sync local and S3 directories using AWS CLI?

‘aws s3 sync ./local-path/ s3://bucket-name/’ can be used to sync four bucket in case of any modifications.



Similar Reads

Create Bucket Policy in AWS S3 Bucket with Python
Bucket policy of s3 bucket means permission and action which can be applied on the particular bucket. AWS S3 has an optional policy that can be used to restrict or grant access to an S3 bucket resource. It is important to note that bucket policies are defined in JSON format. For creating a bucket policy in python we will follow the below steps: Ste
2 min read
How to Create AWS S3 Bucket using CLI ?
Amazon S3 is a Simple Storage Service in AWS that stores files of different types like Photos, Audio, and videos, as objects, providing more scalability and security. It allows users to store and retrieve any amount of data at any point in time from anywhere on the web. It facilitates features such as extremely high availability, security, and simp
6 min read
How to Create Subfolders in S3 Bucket using AWS CLI
The AWS Simple Storage Service (S3) is a cloud service provided by Amazon Web Services (AWS) to store your data securely. There are different approaches to storing and retrieving data from AWS S3; one of them is using the AWS CLI provided by Amazon Web Services. In this article, we will provide you with step-by-step instructions on how to use AWS C
7 min read
How to Delete S3 Bucket from AWS CLI ?
Amazon Simple Storage Service (S3) is a versatile, scalable object storage service given by Amazon Web Services (AWS). It is intended to store and recover any amount of data from any place on the web, offering developers and IT teams a durable, dependable solution for their storage needs. S3 is generally utilized for different purposes, including b
6 min read
AWS Lambda Functions With AWS CLI
Amazon Web Services (AWS) is a comprehensive cloud computing platform offering many services, including storage, computing, databases, and more. AWS Lambda is a serverless computing service provided by Amazon Web Services (AWS). we can create functions and self-contained applications. With AWS Lambda functions, we can perform any kind of computing
5 min read
How To Monitor S3 Bucket Metrics Using AWS CloudWatch ?
Amazon Web Services CloudWatch is a feature-monitoring and management service offered by AWS that helps users better understand the operational health and performance of their AWS cloud resources and applications. Actionable insights are available with CloudWatch for AWS, hybrid, on-premises, and other cloud platforms and infrastructure resources.
4 min read
How To List All AWS S3 Objects In A Bucket Using Java
Amazon Web Services provides its Simple Storage service for uploading data to the cloud. Data in S3 is stored as objects inside buckets. This data can then be used as per the bucket policy. Accessing data through code is one means of processing this stored data in the cloud. In the following sections of this article, we will look at how we can see
6 min read
Mount AWS S3 Bucket On Amazon EC2-Instance
AWS S3 storage service is used for object storage these objects can be termed a file and it's metadata that briefs about it. Well, to store the files and documents we need to create a S3 bucket. It's like a container that stores the files. These files can be pictures, txt file, documents, static web page files, etc. AWS S3 object storage is mostly
3 min read
How to Create Cloudfront Distribution in AWS for S3 Bucket ?
CloudFront is a content delivery network (CDN) service provided by AWS that delivers data, videos, applications, and APIs to viewers with low latency and high transfer speeds. In this article, we will explore how to create a CloudFront distribution in AWS to serve content stored in an S3 bucket. Key TerminologiesCloudFront: Imagine you have a websi
6 min read
How to Access S3 Bucket from Another AWS Account
Amazon Simple Storage Service (S3) is one of the most widely used services provided by Amazon Web Services (AWS). It is a secure and scalable object-based storage solution. Most organizations have multiple AWS accounts that manage different environments, projects, or teams. As a result of this use case, S3 buckets could be managed across various AW
7 min read
Launching an EC2 instance using AWS CLI
In this article, we will look into the process of launching instances that is through AWS CLI(Command Line Interface). AWS CLI is a unified tool for running and managing your various AWS services. Just download and install the tool and you will be able to control multiple AWS services from the command line. For Developers, it is a great tool for ma
5 min read
How To Install and Set Up an AWS CloudWatch Agent Using CLI?
We will see how to install and configure the new unified CloudWatch agent on a running EC2 Linux instance. Collect logs from the Apache HTTP log file and collect metrics from our EC2 instance. New unified CloudWatch can collect both logs and metrics from EC2 instances. The older CloudWatch Logs agent is on the path to deprecation. Features of AWS E
7 min read
How to Get Object in AWS S3 Using UI & CLI ?
The Amazon Web Services (AWS) Simple Storage Service (S3) is a scalable object storage service that allows you to store and retrieve any amount of data at any time. The AWS SDK for JavaScript in Node.js provides the getObject method, which can be used to download objects from S3. This article will show you how to deploy “getObject:aws s3” through t
5 min read
Using Amazon Polly on the AWS CLI
Amazon Polly is a managed service provided by AWS that makes it easy to synthesize speech from text. In this article, we will learn how to use Polly through the AWS CLI. We will learn how to use all the commands available in Polly along with some examples. Using Polly with AWS CLIMake sure you have the latest version of AWS CLI and configured your
8 min read
AWS CLI for SSL/TLS Certificates
An SSL/TLS certificate is a digital object that allows systems to verify the identity & subsequently establish an encrypted network connection to another system using the Secure Sockets Layer/Transport Layer Security (SSL/TLS) protocol. Amazon recommends that you always use a secure connection, but your server is required to have a valid TLS/SS
12 min read
AWS CLI For Identity And Access Management
Amazon Web Services (AWS) is a comprehensive cloud computing platform offering many services, including storage, computing, databases, and more. AWS Identity and Access Management (IAM) is a core AWS service that allows you to securely control who can access your AWS resources and what actions they can perform. IAM enables you to create users, grou
4 min read
How to View Billing Details with AWS CLI: A Step-by-Step Guide
The AWS CLI can help you work with AWS from a command line. Users can control services and do tasks like launch EC2 instances or make S3 buckets. The CLI lets users configure resources for Lambda, EKS, RDS, and more AWS offerings. A big benefit is that users can include CLI commands in scripts, whether shell-based, Python, or other code. This autom
4 min read
How to use AWS CLI in GitHub Actions ?
Through a command-line interface, Amazon offers a powerful tool called the Amazon Web Services Command Line Interface, or AWS CLI, which makes managing AWS resources easier. The importance of this is that it can simplify the process of utilizing AWS services straight from the terminal, removing the requirement to go through the AWS Management Conso
4 min read
How to Upgrade AWS CLI to The Latest Version ?
The AWS Command Line Interface (AWS CLI) is a tool that lets you communicate with AWS services by typing commands into your terminal/shell. It is an effective and practical method for managing resources, automating processes, and carrying out operations on AWS. However, because AWS is continually updating and adding new capabilities to its services
10 min read
Route 53 Realities: AWS CLI For Domain Name System
Amazon Web Services (AWS) is a comprehensive cloud computing platform offering many services, including storage, computing, databases, and more. Amazon Route 53 is a highly available and scalable cloud domain name system (DNS) web service. It is designed for developers and corporations to route end users to Internet applications by translating huma
6 min read
How to Use AWS CLI in Docker Container ?
The AWS Command Line Interface (CLI) is a powerful tool that allows users to interact with AWS services directly from the terminal. Integrating AWS CLI within a Docker container can significantly streamline workflows, especially for development and deployment processes that rely on cloud infrastructure. This article will guide you through the steps
4 min read
Use high-level (s3) commands with the AWS CLI
Amazon Simple Storage Service (Amazon S3) is a generally utilized, versatile, and highly dependable object storage service provided by Amazon Web Services (AWS). S3 allows you to store and recover any measure of data whenever, from anyplace on the web, while the AWS Management Console Center offers an easy to understand interface for managing S3, a
6 min read
What Is AWS CLI (Command Line Interface) ? Complete Guide
AWS CLI is a command line tool that is used for managing the AWS Services from the command line. On downloading the AWS CLI software and configuring it with your AWS credentials you can control the AWS services from the command line and can automate the work through scripts. Whether you are launching EC2 instances, attaching the EBS Volumes, or man
13 min read
AWS CLI for Relational Database Service
As we know, Amazon Web Services (AWS) provides more than 200 IT and infrastructure management services. The question arises: can we only access and manage those services through the AWS Management Console? The answer is no. We can access and interact with those services through the AWS Management Console, which is a web-based interface, the AWS Com
7 min read
DynamoDB Dynamo: AWS CLI Commands for NoSQL Database
As we know, there are three main ways to access and manage AWS services, AWS CLI (command line interface), the AWS Management Console, and the AWS SDK(Software (software kit). Here we are working with the first tool, which is AWS CLI (command line interface) which is basically used for interacting with AWS Resources through scripting and automation
7 min read
How To Download Folder From AWS S3 CLI & UI ?
The AWS Simple Storage Service (S3) is a cloud service provided by Amazon Web Services (AWS) to store your data securely. There are different approaches to storing and retrieving data from AWS S3; one of them is by using AWS CLI provided by Amazon Web Services. In this article, we will provide you with step-by-step instructions on how to use AWS CL
4 min read
Building a 3-tier Web Application Architecture with AWS CLI
As we know, a three-tier architecture has three main layers. Presentation layer, application/business layer, and logic layer. The Presentation layer contains the basic user interface, the application/business layer contains business logic, and the logic layer contains data storage or a database. In this article, we are deep diving into how to build
14 min read
AWS CLI for Serverless Function Management
Serverless computing is changing everything about how we build and deliver applications. No need for the onerous task of managing servers—developers can focus all their attention entirely on writing code and implementing functionalities. Among today's top serverless platforms, AWS Lambda supports running your code in response to events without the
6 min read
How To Read File From Amazon S3 Bucket Using Node.Js ?
The AWS Simple Storage Service (S3) is a cloud service provided by Amazon Web Services (AWS) to store your data securely. There are different approaches to storing and retrieving data from AWS S3; one of them is by using aws-sdk provided by Amazon Web Services. In this article, we will provide you with step-by-step instructions on how to use aws-sd
5 min read
Adding a Bucket Policy by using the Amazon S3 Console
Amazon Simple Storage Service, or Amazon S3, is a service for scalable and secure storage of objects, which are used for the storage, recovery, and delivery of data. Amazon S3 allows you to store and retrieve any amount of data at any time from anywhere on the web. One of the most critical aspects of controlling data in S3 is ensuring that the buck
7 min read