Objective
This guide is designed to familiarize you with the management of your containers/objects. The list of commands presented in this guide are intended to familiarize you with the AWS CLI tool. For more in depth instructions on AWS CLI, please check out the guides here.
Requirements
- A Public Cloud project in your OVHcloud account
- Access to the OVHcloud Control Panel
- An S3 user already created
- Python 3.6 or later (installation instructions)
Instructions
Using AWS CLI
Installation
Note: In this guide, we are using installation on an Ubuntu operating system as an example. For more installation instructions, click this link.
Enter the following command:
user@host:~$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
user@host:~$ unzip awscliv2.zip
user@host:~$ sudo ./aws/install
After installation is complete, run the following command to confirm that the package has been successfully installed.
user@host:~$ aws --version
The output will look something like this with variations based on the version installed.
user@host:~$ aws-cli/2.9.0 Python/3.9.11 Linux/5.4.0-126-generic exe/x86_64.ubuntu.20 prompt/off
Collect Credentials
- To access your S3 resources, you will need your user's Access key and Secret key. You can retrieve this information from the OVHcloud Control Panel under Public Cloud > Object Storage > S3 users.
- You will also need your url_endpoint and the region. If you have already created your container, you can access this information from the
My containers
tab in the details of your container. Otherwise, follow this guide.
Configuration
To configure the aws client, start by using the following command:
user@host:~$ aws configure
Enter the appropriate information for the Access ID, Secret Key, and Region.
You can leave the default output as <none>
user@host:~$ aws configure
AWS Access Key ID [None]: <Your Access ID>
AWS Secret Access Key [None]: <Your Secret Key>
Default region name [None]: <Your Region ID>
Default output format [None]:
Usage
Warning: If you have not installed awscli-plugin-endpoint
, you must add --endpoint-url https://s3.<region_in_lowercase>.perf.cloud.ovh.net
to the command line.
AWS CLI is hard coded to send all requests to an AWS endpoint (target). To send commands to the appropriate target in OVHcloud, the target endpoint information must be included in the command line.
--endpoint-url https://s3.<region_in_lowercase>.perf.cloud.ovh.us
If you have more than one profile, add --profile <profile>
to the command line.
Creating an object container
user@host:~$ aws --endpoint-url https://s3.<region_in_lowercase>.perf.cloud.ovh.us --profile default s3 mb s3://<container_name>
Listing your containers
user@host:~$ aws --endpoint-url https://s3.<region_in_lowercase>.perf.cloud.ovh.us --profile default s3 ls
Uploading a file as an object in your container
user@host:~$ aws -- endpoint-url https://s3.<region_in_lowercase>.perf.cloud.ovh.us default s3 cp ~/<file folder>/<filename> s3://<container_name>
List files in the remote container
user@host:~$ aws --endpoint-url https://s3.<region_in_lowercase>.perf.cloud.ovh.us --profile default s3 ls s3://<container name>
By default, objects are named after files, but can be renamed
user@host:~$ aws --endpoint-url https://s3.<region_in_lowercase>.perf.cloud.ovh.us --profile default s3 mv s3://<container name>/<filename> s3://<container name>/<new-filename>
Downloading an object from a container
user@host:~$ aws --endpoint-url https://s3.<region_in_lowercase>.perf.cloud.ovh.us --profile default s3 cp s3://<source container name>/<filename> ~/<file folder>/<filename>
Uploading an object from one container to another container
user@host:~$ aws --endpoint-url https://s3.<region_in_lowercase>.perf.cloud.ovh.us --profile default s3 cp s3://<source container name>/<filename> s3://<target container name>/
Deleting objects and containers
# Delete an object
user@host:~$ aws --endpoint-url https://s3.<region_in_lowercase>.perf.cloud.ovh.us --profile default s3 rm s3://<container name>/<filename>
# Removing all objects from a container
user@host:~$ aws --endpoint-url https://s3.<region_in_lowercase>.perf.cloud.ovh.us --profile default s3 rm s3://<container name> --recursive
# Delete a storage area. To delete a container, it must be empty.
user@host:~$ aws s3 rb s3://<container_name> --endpoint-url https://s3..perf.cloud.ovh.us --profile default
# If the container is not removed, you can use the same command with the --force option. # This command deletes all objects from the container, then deletes the container.
user@host:~$ aws --endpoint-url https://s3.<region_in_lowercase>.perf.cloud.ovh.us s3 rm s3://<container_name> --force