Use AWS CLI

How to Use the AWS CLI to Interact with OORT Storage S3 Compatible API.

What is AWS CLI?

The AWS CLI or Amazon Web Services Command Line Interface is a command-line tool developed by Amazon in Python to transfer data to an object storage service. This is one of the most used CLI tools for IT system administrators, developers, and programmers. Although this tool was developed by Amazon, you can use it with any S3-compatible API object storage service, including OORT Storage, to manage your storage objects and buckets.

For more information on AWS CLI, see AWS CLI Help.

Prerequisites

Access Key and Access Secret Keys will be stored in the AWS CLI configuration file, but each command needs to reference the API endpoint.

Configure AWS CLI

  1. First, configure the AWS CLI to use OORT Storage. To do this, open a new terminal window. From there, run the command:

aws configure

The command will generate a series of prompts, fill in the following:

  • Access Key ID: Vault Access Key

  • Secret Access Key: Vault Secret Key

  • Region: us-east-1

  • Output Format:Optional

aws configure set default.s3.signature_version s3v4
  1. After completing the prompts, start using the AWS CLI tools to interact with the OORT Storage S3 Compatible API. As long as your access ID and secret access key remain the same, you do not need to configure the AWS CLI again.

All AWS CLI commands will start with the section following this initial command, which will determine what to do and what bucket to use.

OORT Storage Endpoint API:

Standard:https://s3-standard.oortech.com

Archive:https://s3-archive.oortech.com

aws --endpoint https://s3-standard.oortech.com

Crete a bucket

To create a new bucket on OORT Storage using the AWS CLI, use the following command:

aws --endpoint https://s3-standard.oortech.com s3 mb s3://[bucket-name]

For example, to create a new bucket named "mybucket":

aws --endpoint https://s3-standard.oortech.com s3 mb s3://mybucket

Bucket names must be unique across all Oort users, be between 3 and 63 characters long, and can only contain lowercase characters, numbers, and dashes.

The terminal should return the following line:

make_bucket: mybucket

Display buckets

The following command will list all buckets in your Oort account:

aws --endpoint https://s3-standard.oortech.com s3 ls

Upload a file

To upload a single file, use the following command:

aws --endpoint https://s3-standard.oortech.com s3 cp [filename] s3://[bucket-name]

For example, to upload a file named "myphoto.png" to the bucket "mybucket":

aws --endpoint https://s3-standard.oortech.com s3 cp ~/Photos/myphoto.png s3://mybucket

To verify that this file was uploaded by listing the contents of the bucket with the command used earlier: s3 ls

aws --endpoint https://s3-standard.oortech.com s3 ls s3://mybucket

To verify that this file is available from the web console, go to https://console.oortech.com

To upload multiple objects, use the following command:

aws --endpoint https://s3-standard.oortech.com s3 sync [folder name] s3://[bucket-name]

For example, to upload the contents of a folder named "Photos", use the following command:

aws --endpoint https://s3-standard.oortech.com s3 sync ~/Photos/ s3://mybucket/Photos/

List files in a bucket

To list the files of a bucket, use the following command:

aws --endpoint https://s3-standard.oortech.coms3 ls s3://[bucket-name]

For example, to list the files of 'mybucket':

aws --endpoint https://s3-standard.oortech.com s3 ls s3://mybucket

Move a file

To move from bucket 1 to bucket 2, use the following command:

aws --endpoint-url https://s3-standard.oortech.com s3 mv s3://[bucket-name1]/[file-name] s3://[bucket-name2]/

Copy a file

To copy from bucket 1 to bucket 2, use the following command:

aws --endpoint-url https://s3-standard.oortech.com s3 cp s3://[bucket-name1]/[file-name] s3://[bucket-name2]/

Download a file

To download a single file, use the following command:

aws --endpoint https://s3-standard.oortech.com s3 cp s3://[bucket-name]/[file-name] /path/to/download/filename

For example, to download a file named "myphoto.png" from the bucket "mybucket":

aws --endpoint https://s3-standard.oortech.com s3 cp s3://mybucket/Photos/myphoto.png ~/Photos/myphoto.png

Download a folder

To download a folder, use the following command:

aws --endpoint https://s3-standard.oortech.com s3 cp --recursive s3://[bucket-name]/[folder name] /path/to/download/folder

For example, to upload the contents of a folder named "photos", use the following command:

aws --endpoint https://s3-standard.oortech.com s3 cp --recursive s3://mybucket/photos ~/Photos

Delete a file

To delete files, use the following command:

aws --endpoint https://s3-standard.oortech.com s3 rm s3://[bucket_name]/[file_name]

Delete all files in a bucket

To delete all files in the bucket, use the following command:

aws --endpoint https://s3-standard.oortech.com s3 rm --recursive s3://[bucket_name]/

For example, to delete all files from the bucket "mybucket":

aws --endpoint https://s3-standard.oortech.com s3 rm --recursive s3://mybucket/

Generate a presigned S3 URL using the AWS CLI

To create a presigned URL using the AWS CLI, use the following command syntax:

aws s3 --endpoint https://s3-standard.oortech.com presign s3://mybucket/file.name

This command should return a presigned URL. By default, the expiration time is one hour.

You can specify different expiration times by adding flags and minutes. --expires-in

Last updated