Object Storage CLI
  • PDF

Object Storage CLI

  • PDF

Available in Classic and VPC

This guide describes initial settings and brief instructions for Object Storage CLI, which is compatible with Amazon S3 CLI.

Initial settings

It describes how you can install and authenticate Object Storage CLI to use it.

Installation

The installation command is as follows.

pip install awscli==1.15.85
Note

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 in servers with assigned roles, use the authentication key search API among the Metadata API. However, since a timeout can occur during this process, you can use the following command to extend the Metadata API timeout if necessary.

export AWS_METADATA_SERVICE_TIMEOUT=10

The --endpoint-url option is required when using the CLI. For regional call domain, please refer to the Object Storage API Guide.

Commands 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>
    

Search folder size

The option for searching folder size can only be performed with the high-level command. The following is the command to search the folder size.

  • high-level

    aws --endpoint-url=https://kr.object.ncloudstorage.com s3 ls s3://<bucket_name>/<folder_name> --recursive --human-readable --summarize
    

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

    aws --endpoint-url=https://kr.object.ncloudstorage.com s3 rb s3://<bucket_name>
    

    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> --force
    
  • API-level

    aws --endpoint-url=https://kr.object.ncloudstorage.com s3api delete-bucket --bucket <bucket_name>
    
    Note

    API Buckets that are not empty can't be deleted at the API-level.

Sync

The sync feature can only be performed with the 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
    • Sync 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>
      
    • Sync 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>]
      

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 the API-level command. The command is as follows.

  • API-level
    • Set the files in Object Storage bucket as Public

      aws --endpoint-url=https://kr.object.ncloudstorage.com s3api put-object-acl --bucket <bucket_name> --key <object_name> --acl public-read
      
    • Set the files in Object Storage bucket as Private

      aws --endpoint-url=https://kr.object.ncloudstorage.com s3api put-object-acl --bucket <bucket_name> --key <object_name> --acl private
      

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 log file

    aws --endpoint-url=https://kr.object.ncloudstorage.com s3 cp <local_file_path> s3://<bucket_name>[/<object_name>] --debug 2> debug.log
    

CORS settings

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 performed by the API-level command.

The command is as follows.

  • API-level
    • Set CORS rules defined with a JSON file in 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
          }
        ]
      }
      
    • Search CORS rules set in the Object Storage bucket

      aws --endpoint-url=https://kr.object.ncloudstorage.com s3api get-bucket-cors --bucket <bucket_name>
      

Was this article helpful?