Use the AWS CLI with Object Storage

Amazon's AWS CLI is a command-line tool that can be used to interface with the Object Storage service.

📘

This instructions within this guide use AWS CLI version 2. Earlier versions may not work. If you are using version 1 (or earlier), you may want to uninstall it before continuing. See Installing, updating, and uninstalling the AWS CLI (version 1).

Install the AWS CLI

To install the AWS CLI (version 2), navigate to Install, update, and uninstall the AWS CLI and follow the instructions for your operation system. Since there is not currently an official package in any package manager, you typically need to download and install the package manually.

After installing the AWS CLI, you can use the aws s3 command-set as well as the aws s3api (s3api) command-set. The aws s3 command includes a small subset of all of the s3 commands but is easier to use. The aws s3api command includes every s3 operation and allows for advanced configurations. Both commands are used on this page.

Configure the AWS CLI

  1. Run the following command in your preferred terminal:

    aws configure
  2. You are then prompted to fill out a few parameters:

    • AWS Access Key ID: Enter the access key you wish to use. See Manage access keys.
    • AWS Secret Access Key: Enter the secret key that corresponds with the access key. This was displayed once when generating the access key.
    • Default region name: Press enter without inputting any characters to keep the default us region. Do not change this, even if you use Object Storage in region outside the U.S.
    • Default output format: Press enter without inputting any characters.

See the following guides from AWS for more details configuring the CLI: Quick Setup and Configure the AWS CLI.

Additional parameters for AWS CLI commands

  • Endpoint URL: When using the AWS CLI with a non-AWS service, like Object Storage, you must always specify the endpoint url in each command. This is done through the --endpoint parameter. When using the commands in this guide, always replace [endpoint-url] with the URL of the Object Storage endpoint where your bucket resides (or should be created). If you do not know the URL, locate the s3 hostname of your endpoint in the list of endpoints and format it as https://[s3-hostname].

Interact with buckets

List buckets

List all buckets within the data center specified during the configuration process.

Command: aws s3 ls --endpoint=[endpoint-url], replacing [endpoint-url]

Example: List all buckets on the account within the Atlanta data center:

aws s3 ls --endpoint=https://us-southeast-1.linodeobjects.com

Create a bucket

Creates a bucket with the specified bucket label. See the Create and manage buckets guide for rules on naming the bucket.

Command: aws s3 mb s3://[bucket-label] --endpoint=[endpoint-url] --region=[region], replacing [bucket-label], [endpoint-url], and [region] with the values you wish to use for the new bucket.

Example: Create a bucket with the label of "example-bucket" in the Atlanta data center:

aws s3 mb s3://example-bucket --endpoint=https://us-southeast-1.linodeobjects.com --region=us-east-1

Delete a bucket

Deletes the bucket with the specified label.

Command: s3cmd rb s3://[bucket-label], replacing [bucket-label] with the label of the bucket you wish to delete.

Example: Delete the bucket with the label of "example-bucket":

s3cmd rb s3://example-bucket

To delete a bucket that has files in it, include the --recursive (or -r) option and the --force (or -f) option. Use caution when running this command:

s3cmd rb -r -f s3://example-bucket/

Interact with objects

Get object metadata

To retrieve just the metadata for an object (not the object itself), use the head-object command. Akamai Object Storage does not support the get-object-attributes command.

Command: aws s3api head-object --bucket [bucket-label] --key [object-key] --endpoint-url https://[region].linodeobjects.com, replacing [bucket-label], [endpoint-url], and [region] with the values you wish to use for the new bucket.

Example: Retrieve metadata about the object example-file, located within the specified bucket in the Washington DC 2 data center.

aws s3api head-object --bucket example-bucket --key example-file --endpoint-url https://us-iad-18.linodeobjects.com

In the case of a multipart upload, further information about the object can be obtained by running the list-parts command: aws s3api list-parts --bucket [bucket-label] --key [object-key] --upload-id [upload-id] --endpoint-url https://[region].linodeobjects.com. The [upload-id] value is returned when you upload the object using the create-multipart-upload command.