Introduction
In this manual will be considered several base scenarios of using aws-cli command line. The reader should already be familiar with the object storage s3, who also has passed the stage of configuration and setup of aws-cli.
Basic usage
NB! In our examples we use access profile my_user which we’ve created earlier, indicating s3 as used service. Also, the endpoint guideline is installing as https://s3.pilw.io as we use our storage not the Amazon one.
The structure of command line fulfilment is following:
usage: aws [options] <command> <subcommand> [<subcommand> …] [parameters]
The help call for s3 service
$ aws s3 help
NAME
s3 -
DESCRIPTION
This section explains prominent concepts and notations in the set of
high-level S3 commands provided.
...
The help call for Is command of s3 service
$ aws s3 ls help
NAME
ls -
DESCRIPTION
List S3 objects and common prefixes under a prefix or all S3 buckets.
Note that the --output and --no-paginate arguments are ignored for this
command.
...
Obtaining the list of all buckets. (ls command)
$ aws s3 ls --profile=my_user --endpoint=https://s3.pilw.io
2022-03-04 16:03:46 example
2022-03-14 14:55:10 gallery
2022-03-14 16:18:51 tempora
New bucket creation (mb command)
$ aws s3 mb s3://testing_aws_cli --profile=my_user --endpoint=https://s3.pilw.io
make_bucket: testing_aws_cli
Uploading file into bucket (cp command)
First of all, let’s create a new file
$ echo "hello world" > hello.txt
Then download file into the bucket testing_aws_cli, which we’ve created earlier.
$ aws s3 cp hello.txt s3://testing_aws_cli --profile=my_user --endpoint=https://s3.pilw.io
upload: ./hello.txt to s3://testing_aws_cli/hello.txt
Downloading file from the bucket (cp command)
In this particular example testing_aws_cli is a name of bucket and hello.txt is a downloaded file.
$ aws s3 cp s3://testing_aws_cli/hello.txt ./hello.txt.new --profile=my_user --endpoint=https://s3.pilw.io
download: s3://testing_aws_cli/hello.txt to ./hello.txt.new
Deleting a file from the bucket (rm command)
$ aws s3 rm s3://testing_aws_cli/hello.txt --profile=my_user --endpoint=https://s3.pilw.io
delete: s3://testing_aws_cli/hello.txt
Synchronizing local directory with s3 (sync command)
Let’s create a directory and several files in it:
$ mkdir ./example
$ echo 'this is file1' > ./example/file1
$ echo 'this is file2' > ./example/file2
$ echo 'this is file3' > ./example/file3
Now let’s synchronize:
$ aws s3 sync ./example s3://testing_aws_cli/backup/
upload: example/file1 to s3://testing_aws_cli/backup/file1
upload: example/file2 to s3://testing_aws_cli/backup/file2
upload: example/file3 to s3://testing_aws_cli/backup/file3
In this example testing_aws_cli is a name of bucket, /backup is so to say prefix.
NB! There’s no such meaning as directory in s3. But at the same time quite similar behavior can be achieved when using prefixes. We suggest you familiarize with this article: How do I use folders in an S3 Bucket?
Bucket’s content removal
$ aws s3 rm s3://testing_aws_cli --recursive --profile=my_user --endpoint=https://s3.pilw.io
delete: s3://testing_aws_cli/backup/file1
delete: s3://testing_aws_cli/backup/file2
delete: s3://testing_aws_cli/backup/file3
Bucket’s removal
$ aws s3api delete-bucket --bucket testing_aws_cli --endpoint=https://s3.pilw.io
Conclusion
The command line aws cli is a solution of many tasks within s3 storage. You can get more information in links down below and also in a command line documentation (command help)
We suggest you read about s3cmd. It is an alternative command line tool for comfortable working process with s3 storage.