Using s3 commands with aws cli
Frank Promise Edah
Posted on April 18, 2022
This write up describes some of the commands you can use to manage your s3 buckets and objects using aws s3 command line interface.
create a bucket
To create an s3 bucket with the command line, we use s3 mb.
Note that the name given to an s3 bucket must be globally unique. It can contain letter or number, and cannot contain a period next to a hyphen or another period.
syntax
$ aws s3 mb [--options]
example
aws s3 mb s3://bucket-name
2. list buckets and objects
$ aws s3 ls
Using this command without an option attached list all buckets.
To list the object contained in specific folder(prefix)
$ aws ls s3://bucket-name/example/
3. Delete bucket
$ aws s3 rb s3://bucket-name
By default, AWS does not allow you delete a bucket that is not empty. In order to by pass that, you must add --force option. However, if versioning is enabled in the bucket, then even this option won't work.
4. Move objects
To move a folder in an s3 bucket to another s3 bucket, use:
$ aws s3 mv s3://bucket-name/example s3://my-bucket/
To move a local file from your current working directory to the Amazon S3 bucket:
aws s3 mv filename.txt s3://bucket-name
To move a file from your Amazon S3 bucket to your current working directory:
aws s3 mv s3://bucket-name/filename.txt ./
5. Copy objects
To copy objects in an s3 bucket to another:
$ aws s3 cp s3://bucket-name/example s3://my-bucket/
To copy a local file from your current working directory to the Amazon S3 bucket:
$ aws s3 cp filename.txt s3://bucket-name
Posted on April 18, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 30, 2024