-
Print
-
PDF
Object Storage CLI
-
Print
-
PDF
Available in Classic and VPC
This guide describes initial settings and brief instructions for the Object Storage CLI, which is compatible with the Amazon S3 CLI.
Initial settings
It describes how you can install and authenticate the Object Storage CLI to use it.
Install
The installation command is as follows.
pip install awscli==1.15.85
- Since awscli version 1.16.x does not support some feature, we recommend using version 1.15.x.
- awscli version 1.15.85 supports Python 3.8 or earlier.
- Refer to the following for related documents.
Authenticate
The following describes how to set the authentication information.
~$ aws configure
AWS Access Key ID [****************leLy]: ACCESS_KEY_ID
AWS Secret Access Key [None]: SECRET_KEY
Default region name [None]: [Enter]
Default output format [None]: [Enter]
Precautions
It describes precautions when using it in servers with assigned roles. Servers with assigned roles can use Object Storage commands without additional configurations.
When using it in servers with assigned roles, use the authentication key search API among metadata APIs. However, since a timeout can occur during this process, you can use the following command to increate the metadata API timeout if necessary.
export AWS_METADATA_SERVICE_TIMEOUT=10
The --endpoint-url option is required when using the CLI. For calling domains by region, refer to the Object Storage API Guide.
Command help
Run the following command to check help for smooth use of Object Storage CLI.
aws help
aws <command> help
aws <command> <subcommand> help
Commands
It describes the Object Storage CLI.
Search bucket list
The following is the command to search the bucket list.
- high-level
aws --endpoint-url=https://kr.object.ncloudstorage.com s3 ls
- API-level
aws --endpoint-url=https://kr.object.ncloudstorage.com s3api list-buckets
Search object list
The following is the command to search the object list.
-
high-level
aws --endpoint-url=https://kr.object.ncloudstorage.com s3 ls s3://<bucket_name>
-
API-level
aws --endpoint-url=https://kr.object.ncloudstorage.com s3api list-objects --bucket <bucket_name>
Upload object
The following is the command to upload an object.
- high-level
aws --endpoint-url=https://kr.object.ncloudstorage.com s3 cp <local_file_path> s3://<bucket_name>[/<object_name>]
- API-level
aws --endpoint-url=https://kr.object.ncloudstorage.com s3api put-object --bucket <bucket_name> --key <object_name> --body <local_file_path>
Delete object
The following is the command to delete an object.
- high-level
aws --endpoint-url=https://kr.object.ncloudstorage.com s3 rm s3://<bucket_name>/<object_name>
- API-level
aws --endpoint-url=https://kr.object.ncloudstorage.com s3api delete-object --bucket <bucket_name> --key <object_name>
Delete bucket
The following is the command to delete a bucket.
- high-level
You can delete a bucket that is not empty by adding the force option. Delete all objects that belong to a bucket before deleting the bucket.aws --endpoint-url=https://kr.object.ncloudstorage.com s3 rb s3://<bucket_name>
aws --endpoint-url=https://kr.object.ncloudstorage.com s3 rb s3://<bucket_name> --force
- API-level
aws --endpoint-url=https://kr.object.ncloudstorage.com s3api delete-bucket --bucket <bucket_name>
NoteBuckets that are not empty can't be deleted at the API-level.
Sync
The sync feature can only be performed with a high-level command. If you use the --delete option, then the files that don't exist in the source are also deleted in the destination. The sync command is as follows.
- high-level
- Syncs all files in an Object Storage bucket (folder) to a local directory
aws --endpoint-url=https://kr.object.ncloudstorage.com s3 sync s3://<bucket_name>[/<object_name>] <local_directory_name>
- Syncs all files in a local directory to an Object Storage bucket (folder)
aws --endpoint-url=https://kr.object.ncloudstorage.com s3 sync <local_directory_name> s3://<bucket_name>[/<object_name>]
- Sync all files in an Object Storage bucket (folder) to another bucket (folder)
aws --endpoint-url=https://kr.object.ncloudstorage.com s3 sync s3://<source_bucket_name>[/<destination_object_name>] s3://<destination_bucket_name>[/<destination_object_name>]
- Syncs all files in an Object Storage bucket (folder) to a local directory
Access control list (ACL)
You can set access control list (ACL) permissions for files in an Object Storage bucket (folder). The ACL feature can only be performed with an API-level command. The commands are as follows.
- API-level
- Sets files in an Object Storage bucket to [Public]
aws --endpoint-url=https://kr.object.ncloudstorage.com s3api put-object-acl --bucket <bucket_name> --key <object_name> --acl public-read
- Sets files in an Object Storage bucket to [Private]
aws --endpoint-url=https://kr.object.ncloudstorage.com s3api put-object-acl --bucket <bucket_name> --key <object_name> --acl private
- Sets files in an Object Storage bucket to [Public]
Debugging
The commands related to debugging are as follows.
- View detailed logs using the --debug* option
aws --endpoint-url=https://kr.object.ncloudstorage.com s3 cp <local_file_path> s3://<bucket_name>[/<object_name>] --debug
- Save as a log file
aws --endpoint-url=https://kr.object.ncloudstorage.com s3 cp <local_file_path> s3://<bucket_name>[/<object_name>] --debug 2> debug.log
Set CORS
It sets Cross-Origin Resource Sharing (CORS) for an Object Storage bucket. Once an Object Storage bucket receives a cross-origin request, it checks the CORS configuration, and allows the cross-origin request using the first CORS rule that matches the browser request. The following conditions have to be met for a CORS rule to be matched.
-
The request's Origin header must match the AllowedOrigins element.
-
The request method or Access-Control-Request-Method header (preflight request) must match the AllowedMethods element.
-
All headers specified in the Access-Control-Request-Method header (preflight request) must match the AllowedHeaders element. CORS configuration can only be done by an API-level command. The command is as follows.
-
API-level
- Sets CORS rules defined with a JSON file to the Object Storage bucket
aws --endpoint-url=https://kr.object.ncloudstorage.com s3api put-bucket-cors --bucket <bucket_name> --cors-configuration file://cors.json cors.json: { "CORSRules": [ { "AllowedHeaders": ["*"], "AllowedMethods": ["GET","PUT"], "AllowedOrigins": ["*"], "MaxAgeSeconds": 3000 } ] }
- Searches the CORS rules set on the Object Storage bucket
aws --endpoint-url=https://kr.object.ncloudstorage.com s3api get-bucket-cors --bucket <bucket_name>
- Sets CORS rules defined with a JSON file to the Object Storage bucket