---
title: "How To Create a AWS S3 Bucket Using AWS CLI"
lang: "en"
author: "Mohammad Abu Mattar"
canonical: https://mkabumattar.com/post/how-to-create-a-aws-s3-bucket-using-aws-cli
---

![Blog post image for How To Create a AWS S3 Bucket Using AWS CLI - In this post, I will show you how to create a AWS S3 bucket using AWS CLI.](/_astro/hero.CDw8keBv_ZUM9wk.webp)

[Home](/)›[Blog](/blog)›[All Categories](/blog/categories)›[AWS](/blog/categories/aws)

Blog

[Prev in AWSHow to Create a AWS RDS MySQL Database and Connect to it using MySQL Workbench](/blog/post/how-to-create-a-aws-rds-mysql-database-and-connect-to-it-using-mysql-workbench)[Next in AWSHow To Create A Custom VPC Using AWS CLI](/blog/post/how-to-create-a-custom-vpc-using-aws-cli)

[AWS](/blog/categories/aws)[S3](/blog/categories/s3)[AWS CLI](/blog/categories/aws-cli)[Cloud Storage](/blog/categories/cloud-storage)

# How To Create a AWS S3 Bucket Using AWS CLI

[Mohammad Abu Mattar](/authors/mohammad-abu-mattar)Published: 11 Nov 202203 Mins read07 Mins listen

[Markdown for AI(opens in a new tab)](/post/how-to-create-a-aws-s3-bucket-using-aws-cli/index.md "Open the plain-Markdown version of this page, for pasting into an AI tool")

TL;DR

In this post, I will show you how to create a AWS S3 bucket using AWS CLI.

Series

[AWS CLI Guides](/series/aws-cli-guides)4/4

[PreviousHow To Create a DynamoDB Table Using AWS CLI](/blog/post/how-to-create-a-dynamodb-table-using-aws-cli)

All posts in this series (4)

Blog4

1.  [How To Create A Custom VPC Using AWS CLI](/blog/post/how-to-create-a-custom-vpc-using-aws-cli)
2.  [How To Create An AWS EC2 Instance Using AWS CLI](/blog/post/how-to-create-an-aws-ec2-instance-using-aws-cli)
3.  [How To Create a DynamoDB Table Using AWS CLI](/blog/post/how-to-create-a-dynamodb-table-using-aws-cli)
4.  [How To Create a AWS S3 Bucket Using AWS CLIYou are here](/blog/post/how-to-create-a-aws-s3-bucket-using-aws-cli)

### How To Create a AWS S3 Bucket Using AWS CLI

Contents

[Introduction](#introduction)[Prerequisites](#prerequisites)[AWS S3 bucket](#aws-s3-bucket)[Step 1: create an AWS S3 bucket](#step-1-create-an-aws-s3-bucket)[Step 2: list AWS S3 buckets](#step-2-list-aws-s3-buckets)[Step 3: upload a file to an AWS S3 bucket](#step-3-upload-a-file-to-an-aws-s3-bucket)[Step 4: download a file from an AWS S3 bucket](#step-4-download-a-file-from-an-aws-s3-bucket)[Step 5: sync a local directory with an AWS S3 bucket](#step-5-sync-a-local-directory-with-an-aws-s3-bucket)[Step 6: sync an AWS S3 bucket with a local directory](#step-6-sync-an-aws-s3-bucket-with-a-local-directory)[Step 7: list files in an AWS S3 bucket](#step-7-list-files-in-an-aws-s3-bucket)[Step 8: move a file in an AWS S3 bucket](#step-8-move-a-file-in-an-aws-s3-bucket)[Step 9: presign a URL for an AWS S3 bucket](#step-9-presign-a-url-for-an-aws-s3-bucket)[Step 10: delete a file from an AWS S3 bucket](#step-10-delete-a-file-from-an-aws-s3-bucket)[Step 11: delete an AWS S3 bucket](#step-11-delete-an-aws-s3-bucket)[Step 12: static website hosting](#step-12-static-website-hosting)[Conclusion](#conclusion)[References](#references)

## [Introduction](#introduction)

In this post, I will show you how to create an AWS S3 bucket using AWS CLI.

## [Prerequisites](#prerequisites)

You need to have:

-   AWS CLI installed and configured
-   AWS S3 bucket name

## [AWS S3 bucket](#aws-s3-bucket)

### [Step 1: create an AWS S3 bucket](#step-1-create-an-aws-s3-bucket)

To create an AWS S3 bucket, run the following command:

Terminal window

```
1aws s3 mb s3://<BUCKET_NAME>
```

Explanation:

-   `aws s3 mb` - Create a bucket
-   `s3://<BUCKET_NAME>` - Bucket name

Note

-   The bucket name must be unique across all existing bucket names in Amazon S3.
-   You can use the `--region` option to specify the region where the bucket will be created.

### [Step 2: list AWS S3 buckets](#step-2-list-aws-s3-buckets)

To list all AWS S3 buckets, run the following command:

Terminal window

```
1aws s3 ls
```

Explanation:

-   `aws s3 ls` - List all buckets

### [Step 3: upload a file to an AWS S3 bucket](#step-3-upload-a-file-to-an-aws-s3-bucket)

To upload a file to an AWS S3 bucket, run the following command:

Terminal window

```
1aws s3 cp <FILE_PATH> s3://<BUCKET_NAME>
```

Explanation:

-   `aws s3 cp` - Copy an object
-   `<FILE_PATH>` - File path in your local machine
-   `s3://<BUCKET_NAME>` - Bucket name where the file will be uploaded

### [Step 4: download a file from an AWS S3 bucket](#step-4-download-a-file-from-an-aws-s3-bucket)

To download a file from an AWS S3 bucket, run the following command:

Terminal window

```
1aws s3 cp s3://<BUCKET_NAME>/<FILE_NAME> <FILE_PATH>
```

Explanation:

-   `aws s3 cp` - Copy an object
-   `s3://<BUCKET_NAME>/<FILE_NAME>` - Bucket name and file name where the file will be downloaded from
-   `<FILE_PATH>` - File path in your local machine

### [Step 5: sync a local directory with an AWS S3 bucket](#step-5-sync-a-local-directory-with-an-aws-s3-bucket)

To sync a local directory with an AWS S3 bucket, run the following command:

Terminal window

```
1aws s3 sync <LOCAL_DIRECTORY_PATH> s3://<BUCKET_NAME>
```

Explanation:

-   `aws s3 sync` - Sync a local directory with an S3 bucket
-   `<LOCAL_DIRECTORY_PATH>` - Local directory path in your local machine
-   `s3://<BUCKET_NAME>` - Bucket name that the local directory will be synced to

### [Step 6: sync an AWS S3 bucket with a local directory](#step-6-sync-an-aws-s3-bucket-with-a-local-directory)

To sync an AWS S3 bucket with a local directory, run the following command:

Terminal window

```
1aws s3 sync s3://<BUCKET_NAME> <LOCAL_DIRECTORY_PATH>
```

Explanation:

-   `aws s3 sync` - Sync an S3 bucket with a local directory
-   `s3://<BUCKET_NAME>` - Bucket name that will be synced to the local directory
-   `<LOCAL_DIRECTORY_PATH>` - Local directory path in your local machine

### [Step 7: list files in an AWS S3 bucket](#step-7-list-files-in-an-aws-s3-bucket)

To list all files in an AWS S3 bucket, run the following command:

Terminal window

```
1aws s3 ls s3://<BUCKET_NAME>
```

Explanation:

-   `aws s3 ls` - List all objects in a bucket
-   `s3://<BUCKET_NAME>` - Bucket name

### [Step 8: move a file in an AWS S3 bucket](#step-8-move-a-file-in-an-aws-s3-bucket)

To move a file in an AWS S3 bucket, run the following command:

Terminal window

```
1aws s3 mv s3://<BUCKET_NAME>/<FILE_NAME> s3://<BUCKET_NAME>/<NEW_FILE_NAME>
```

Explanation:

-   `aws s3 mv` - Move an object
-   `s3://<BUCKET_NAME>/<FILE_NAME>` - Bucket name and file name where the file will be moved from
-   `s3://<BUCKET_NAME>/<NEW_FILE_NAME>` - Bucket name and new file name where the file will be moved to

### [Step 9: presign a URL for an AWS S3 bucket](#step-9-presign-a-url-for-an-aws-s3-bucket)

To presign a URL for an AWS S3 bucket, run the following command:

Terminal window

```
1aws s3 presign s3://<BUCKET_NAME>/<FILE_NAME>
```

Explanation:

-   `aws s3 presign` - Generate a presigned URL for an Amazon S3 object or a bucket
-   `s3://<BUCKET_NAME>/<FILE_NAME>` - Bucket name and file name where the file will be presigned

Note

-   You can use the `--expires-in` option to specify the number of seconds before the presigned URL expires.
-   You can use the `--region` option to specify the region where the bucket is located.

### [Step 10: delete a file from an AWS S3 bucket](#step-10-delete-a-file-from-an-aws-s3-bucket)

To delete a file from an AWS S3 bucket, run the following command:

Terminal window

```
1aws s3 rm s3://<BUCKET_NAME>/<FILE_NAME>
```

Explanation:

-   `aws s3 rm` - Remove an object
-   `s3://<BUCKET_NAME>/<FILE_NAME>` - Bucket name and file name where the file will be deleted from

### [Step 11: delete an AWS S3 bucket](#step-11-delete-an-aws-s3-bucket)

To delete an AWS S3 bucket, run the following command:

Terminal window

```
1aws s3 rb s3://<BUCKET_NAME>
```

Explanation:

-   `aws s3 rb` - Remove a bucket
-   `s3://<BUCKET_NAME>` - Bucket name

Note

-   You can use the `--force` option to delete a non-empty bucket.
-   You can use the `--region` option to specify the region where the bucket is located.

### [Step 12: static website hosting](#step-12-static-website-hosting)

To host a static website on an AWS S3 bucket, run the following command:

Terminal window

```
1aws s3 website s3://<BUCKET_NAME> --index-document <INDEX_DOCUMENT> --error-document <ERROR_DOCUMENT>
```

Explanation:

-   `aws s3 website` - Set the configuration of a bucket for website hosting
-   `s3://<BUCKET_NAME>` - Bucket name
-   `--index-document` - The name of the index document (for example, index.html)
-   `--error-document` - The name of the error document (for example, error.html)

Note

-   You can use the `--region` option to specify the region where the bucket is located.

## [Conclusion](#conclusion)

In this tutorial, you learned how to use the AWS CLI to manage AWS S3 buckets. You also learned how to upload, download, sync, list, move, presign, and delete files in AWS S3 buckets.

## [References](#references)

-   [Amazon S3 User Guide](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html)
-   [AWS CLI Command Reference - s3](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3/index.html)
-   [AWS CLI Command Reference - s3api](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/index.html) (for more granular S3 operations)
-   [Working with Amazon S3 Buckets](https://docs.aws.amazon.com/AmazonS3/latest/userguide/UsingBucket.html)
-   [Uploading Objects to Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/UploadingObjects.html)
-   [Downloading an Object from Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/download-objects.html)
-   [Syncing Folders with Amazon S3](https://docs.aws.amazon.com/cli/latest/userguide/cli-services-s3-commands.html#using-s3-commands-managing-objects-sync)
-   [Listing Keys in an Amazon S3 Bucket](https://docs.aws.amazon.com/AmazonS3/latest/userguide/ListingKeysUsingAPIs.html)
-   [Generating a Presigned URL for an S3 Object](https://docs.aws.amazon.com/AmazonS3/latest/userguide/ShareObjectPreSignedURL.html)
-   [Deleting Objects from Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/DeletingObjects.html)
-   [Deleting an S3 Bucket](https://docs.aws.amazon.com/AmazonS3/latest/userguide/delete-bucket.html)
-   [Hosting a Static Website on Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/WebsiteHosting.html)
-   [AWS CLI User Guide](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html)
-   [Bucket Naming Rules - Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html)

Was this useful?

## Tags

[#AWS S3 Bucket](/blog/tags/aws-s3-bucket)[#AWS CLI Commands](/blog/tags/aws-cli-commands)[#S3 Management](/blog/tags/s3-management)[#Cloud Storage CLI](/blog/tags/cloud-storage-cli)[#Object Storage](/blog/tags/object-storage)[#Static Website Hosting S3](/blog/tags/static-website-hosting-s3)

## Share

[Facebook](https://facebook.com/sharer/sharer.php?u=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-create-a-aws-s3-bucket-using-aws-cli "Share on Facebook")[Twitter](https://twitter.com/intent/tweet/?text=How%20To%20Create%20a%20AWS%20S3%20Bucket%20Using%20AWS%20CLI&url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-create-a-aws-s3-bucket-using-aws-cli "Share on Twitter")[LinkedIn](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-create-a-aws-s3-bucket-using-aws-cli&title=How%20To%20Create%20a%20AWS%20S3%20Bucket%20Using%20AWS%20CLI&summary=In%20this%20post%2C%20I%20will%20show%20you%20how%20to%20create%20a%20AWS%20S3%20bucket%20using%20AWS%20CLI.&source=https://mkabumattar.com "Share on LinkedIn")[WhatsApp](https://wa.me/?text=How%20To%20Create%20a%20AWS%20S3%20Bucket%20Using%20AWS%20CLI%20https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-create-a-aws-s3-bucket-using-aws-cli "Share on WhatsApp")[Telegram](https://t.me/share/url?url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-create-a-aws-s3-bucket-using-aws-cli&text=How%20To%20Create%20a%20AWS%20S3%20Bucket%20Using%20AWS%20CLI "Share on Telegram")[Reddit](https://www.reddit.com/submit?url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-create-a-aws-s3-bucket-using-aws-cli&title=How%20To%20Create%20a%20AWS%20S3%20Bucket%20Using%20AWS%20CLI "Share on Reddit")[Hacker News](http://news.ycombinator.com/submitlink?u=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-create-a-aws-s3-bucket-using-aws-cli&t=How%20To%20Create%20a%20AWS%20S3%20Bucket%20Using%20AWS%20CLI "Share on Hacker News")[Pinterest](https://pinterest.com/pin/create/button/?url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-create-a-aws-s3-bucket-using-aws-cli&media=&description=In%20this%20post%2C%20I%20will%20show%20you%20how%20to%20create%20a%20AWS%20S3%20bucket%20using%20AWS%20CLI. "Share on Pinterest")[Email](<mailto:?subject=How%20To%20Create%20a%20AWS%20S3%20Bucket%20Using%20AWS%20CLI&body=Check out this article: https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-create-a-aws-s3-bucket-using-aws-cli>)

## Comments

## You might also enjoy

More posts on similar topics

[![How To Create a DynamoDB Table Using AWS CLI](/_astro/hero.DFm0nlBr_ZmQrVw.webp)](/blog/post/how-to-create-a-dynamodb-table-using-aws-cli)

## [How To Create a DynamoDB Table Using AWS CLI](/blog/post/how-to-create-a-dynamodb-table-using-aws-cli)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [DynamoDB](/blog/categories/dynamodb)
-   [AWS CLI](/blog/categories/aws-cli)
-   [NoSQL Databases](/blog/categories/nosql-databases)

Introduction In this article, we will learn how to create a DynamoDB table using AWS CLI. We will also learn how to add items to the table and how to query the table. Prerequisites To follow

[#AWS DynamoDB](/blog/tags/aws-dynamodb)[#AWS CLI Commands](/blog/tags/aws-cli-commands)[#NoSQL](/blog/tags/nosql)+4 tags

[read more](/blog/post/how-to-create-a-dynamodb-table-using-aws-cli)

[![How To Create A Custom VPC Using AWS CLI](/_astro/hero.BWXhtVCk_Z2s3b7P.webp)](/blog/post/how-to-create-a-custom-vpc-using-aws-cli)

## [How To Create A Custom VPC Using AWS CLI](/blog/post/how-to-create-a-custom-vpc-using-aws-cli)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [VPC](/blog/categories/vpc)
-   [AWS CLI](/blog/categories/aws-cli)
-   [Cloud Networking](/blog/categories/cloud-networking)
-   [Infrastructure as Code](/blog/categories/infrastructure-as-code)

Introduction The example below creates a VPC with an IPv4 CIDR block, a public subnet, and a private subnet, all with AWS CLI commands. Once the VPC and subnets are configured, you can run an inst

[#AWS VPC](/blog/tags/aws-vpc)[#AWS CLI Commands](/blog/tags/aws-cli-commands)[#Virtual Private Cloud](/blog/tags/virtual-private-cloud)+7 tags

[read more](/blog/post/how-to-create-a-custom-vpc-using-aws-cli)

[![How To Create An AWS EC2 Instance Using AWS CLI](/_astro/hero.Dh2x9Phr_14dc4A.webp)](/blog/post/how-to-create-an-aws-ec2-instance-using-aws-cli)

## [How To Create An AWS EC2 Instance Using AWS CLI](/blog/post/how-to-create-an-aws-ec2-instance-using-aws-cli)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [EC2](/blog/categories/ec2)
-   [VPC](/blog/categories/vpc)
-   [AWS CLI](/blog/categories/aws-cli)
-   [WordPress](/blog/categories/wordpress)
-   [Linux](/blog/categories/linux)

Introduction In this tutorial we will create an AWS EC2 instance with the AWS CLI. We will build the network around it first, then launch the instance with a user data script that installs the Apa

[#AWS CLI EC2](/blog/tags/aws-cli-ec2)[#AWS CLI VPC](/blog/tags/aws-cli-vpc)[#VPC Configuration](/blog/tags/vpc-configuration)+8 tags

[read more](/blog/post/how-to-create-an-aws-ec2-instance-using-aws-cli)

[![How To Connect A Two EC2 Instances Data Transfer Using AWS CLI Without AWS EFS](/_astro/hero.WG5UXtzN_2uuusz.webp)](/blog/post/how-to-connect-a-two-ec2-instances-data-transfer-using-aws-cli-without-aws-efs)

## [How To Connect A Two EC2 Instances Data Transfer Using AWS CLI Without AWS EFS](/blog/post/how-to-connect-a-two-ec2-instances-data-transfer-using-aws-cli-without-aws-efs)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [EC2](/blog/categories/ec2)
-   [S3](/blog/categories/s3)
-   [Data Transfer](/blog/categories/data-transfer)
-   [AWS CLI](/blog/categories/aws-cli)

Introduction In this post, I will show you how to transfer data between two EC2 instances using AWS CLI, without AWS EFS. We will use an AWS S3 bucket as the middleman. We will create an AWS S3 b

[#AWS S3 Sync](/blog/tags/aws-s3-sync)[#EC2 Data Transfer](/blog/tags/ec2-data-transfer)[#AWS CLI Automation](/blog/tags/aws-cli-automation)+5 tags

[read more](/blog/post/how-to-connect-a-two-ec2-instances-data-transfer-using-aws-cli-without-aws-efs)

[![How To Setup Bastion Host on AWS using AWS CLI](/_astro/hero.DGhoBA0r_KL9IM.webp)](/blog/post/how-to-setup-bastion-host-on-aws-using-aws-cli)

## [How To Setup Bastion Host on AWS using AWS CLI](/blog/post/how-to-setup-bastion-host-on-aws-using-aws-cli)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [AWS CLI](/blog/categories/aws-cli)
-   [Security](/blog/categories/security)
-   [Networking](/blog/categories/networking)
-   [DevOps](/blog/categories/devops)

Introduction Security is the top priority for any infrastructure and application, and that's why a Bastion host is a must-have in your infrastructure if you want to secure your remote connections.

[#AWS Bastion Host](/blog/tags/aws-bastion-host)[#AWS CLI](/blog/tags/aws-cli)[#VPC Setup](/blog/tags/vpc-setup)+7 tags

[read more](/blog/post/how-to-setup-bastion-host-on-aws-using-aws-cli)

[![How to Create a AWS RDS MySQL Database and Connect to it using MySQL Workbench](/_astro/hero.BalpSU3D_jRzSY.webp)](/blog/post/how-to-create-a-aws-rds-mysql-database-and-connect-to-it-using-mysql-workbench)

## [How to Create a AWS RDS MySQL Database and Connect to it using MySQL Workbench](/blog/post/how-to-create-a-aws-rds-mysql-database-and-connect-to-it-using-mysql-workbench)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [RDS](/blog/categories/rds)
-   [MySQL](/blog/categories/mysql)
-   [Database Management](/blog/categories/database-management)
-   [Cloud Computing](/blog/categories/cloud-computing)

Introduction RDS is a managed service that makes it easy to set up, operate, and scale a relational database in the cloud. It provides cost-efficient and resizable capacity while automating time-c

[#AWS RDS Setup](/blog/tags/aws-rds-setup)[#MySQL Workbench Connection](/blog/tags/mysql-workbench-connection)[#Relational Database](/blog/tags/relational-database)+4 tags

[read more](/blog/post/how-to-create-a-aws-rds-mysql-database-and-connect-to-it-using-mysql-workbench)

6 related posts
