Sheet 02 · BlogSurveyed 2026

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.

How To Create a AWS S3 Bucket Using AWS CLI

Published: 03 Mins read07 Mins listen
Markdown for AI(opens in a new tab)

Introduction

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

Prerequisites

You need to have:

  • AWS CLI installed and configured
  • AWS S3 bucket name

AWS S3 bucket

Step 1: create an AWS S3 bucket

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

Terminal window
aws 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

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

Terminal window
aws s3 ls

Explanation:

  • aws s3 ls - List all buckets

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
aws 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

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

Terminal window
aws 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

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

Terminal window
aws 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

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

Terminal window
aws 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

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

Terminal window
aws 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

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

Terminal window
aws 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

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

Terminal window
aws 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

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

Terminal window
aws 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

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

Terminal window
aws 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

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

Terminal window
aws 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

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

Was this useful?

You might also enjoy

More posts on similar topics

How To Create a DynamoDB Table Using AWS CLI

How To Create a DynamoDB Table Using AWS CLI

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

How To Create A Custom VPC Using AWS CLI

How To Create A Custom VPC Using AWS CLI

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

How To Create An AWS EC2 Instance Using AWS CLI

How To Create An AWS EC2 Instance Using AWS CLI

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

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

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

How To Setup Bastion Host on AWS using AWS CLI

How To Setup Bastion Host on AWS using AWS CLI

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.

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

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

6 related posts