API
The Gcore Customer Portal is being updated. Screenshots may not show the current version.
Storage
Storage
Chosen image
Home/Storage/Manage Object Storage/Configure AWS CLI, S3cmd, and AWS JavaScript SDK/Connect external command lines

Connect AWS CLI, S3cmd, and AWS JavaScript SDK

With Gcore Object Storage, you can utilize S3-compatible software, such as AWS CLI and S3cmd.

AWS CLI

AWS CLI, or the AWS Command Line Interface, is the software for managing AWS services and has been integrated with our Object Storage for managing your buckets using commands from Amazon's official documentation.

Install AWS CLI

1. Follow the instructions in the Amazon article to install the latest version of the AWS CLI.

2. To verify that the installation was successful, run the aws --version command in the terminal.

aws --version

The installation was successful if you see the version and your operating system in the output. For example:

aws-cli/2.7.24 Python/3.8.8 Windows/10 exe/AMD64 prompt/off 

If the terminal cannot find the "aws" command, there may have been an issue during the installation. Please refer to the "Troubleshooting AWS CLI errors" guide for assistance.

Configure your storage for use with AWS CLI

1. Enter the aws configure command, and a configuration wizard will be launched.

2. You need to provide the following information:

  • Access Key: Enter the access key you received after creating the storage in your account.
  • Secret Key: Enter the secret key you received after creating the storage in your account.
  • Default region name: Enter your storage region, for example, s-ed1.

Note: Do not change the other parameters.

3. To verify the configuration was successful, run the following command:

aws s3 ls --endpoint-url=https://s-ed1.cloud.gcore.lu

Replace https://s-ed1.cloud.gcore.lu with your storage endpoint, which can be found in the "S3 service URLs and default region names" guide.

Since there are no buckets in the storage, the command will not list anything. However, if there are no errors, you have configured the credentials correctly.

S3cmd

S3cmd is a free command line tool for uploading, retrieving, and managing data in Amazon S3 and other cloud storage services. Please use the commands described in the official S3cmd documentation.

Install S3cmd

1. Go to the "Download" section in the S3cmd documentation.

2. Download the repository for your operating system.

3. Install the latest version of S3cmd.

Configure your storage for use with S3cmd

Configure with the wizard

1. Enter the following command to launch the configuration wizard:

s3cmd --configure

2. You need to specify the following information:

  • Access Key: Enter the access key you received after creating the storage in your account.
  • Secret Key: Enter the secret key you received after creating the storage in your account.
  • S3 Endpoint: Enter your storage URL, for example, s-ed1.cloud.gcore.lu.
  • DNS-style bucket+hostname: Enter your storage URL, for example, s-ed1.cloud.gcore.lu. Optionally specify the port template for accessing a bucket in the format: s-ed1.cloud.gcore.lu:80.

Note: Do not change the other parameters.

S3cmd will try to connect to your storage. If the data is entered correctly, you'll receive the message:

Success. Your access key and secret key worked fine :-)

S3cmd will save the entered information in the ~/.s3cfg file in the following format:

[default]  
access_key = 123ABC456DEF...  
secret_key = EXAMPLE...  
host_base = s-ed1.cloud.gcore.lu  
host_bucket = s-ed1.cloud.gcore.lu

Configure without the wizard

This method allows you to enter configuration data in one line without using a wizard.

Enter the command:

s3cmd --access_key 12*****6DEF --secret_key EX***** --host s-ed1.cloud.gcore.lu --host-bucket s-ed1.cloud.gcore.lu

Where:

  • 12*****6DEF is the access key you received after creating the storage in your account.
  • EXAMPLE***** is the secret key you received after creating the storage in your account.
  • s-ed1.cloud.gcore.lu is the storage URL.

AWS JavaScript SDK

The methods described below are relevant for AWS JavaScript SDK version 2.742.0.

Connect AWS JavaScript SDK

To connect the interface with your storage, add AWS SDK to your HTML page according to the following example:

<html>   
    <head>   
        <script src="[https://sdk.amazonaws.com/js/aws-sdk-2.742.0.min.js](https://sdk.amazonaws.com/js/aws-sdk-2.742.0.min.js)"></script>   
        <script src="./js/index2.js"></script>   
    </head>   
    <body>   
        <h1>List of files</h1>   
        <ul id="list">   
        </ul>   
    </body>   
</html> 

Manage storage with AWS JavaScript SDK

Configure storage and create an S3 bucket

Open the configuration file (./js/index2.js) and specify the data of your storage and future bucket:

var s3BucketName = "test";   
var host = "https://s-ed1.cloud.gcore.lu";   
var access\_key = "1234";   
var secret\_key = "5678";   
    
AWS.config.accessKeyId = access\_key;   
AWS.config.secretAccessKey = secret\_key;   
AWS.config.endpoint = host;   
  
var s3 = new AWS.S3({   
    sslEnabled: true   
  }); 

Where:

  • test is the name of the future bucket;
  • https://s-ed1.cloud.gcore.lu is the storage URL;
  • 1234 is the access key you received when creating the storage in the Gcore Customer Portal.
  • 5678 is the secret key you received when creating the storage in the Gcore Customer Portal.

Set CORS policy on a bucket

Below is the wildcard policy example. It describes a configuration that allows cross-origin GET HEAD PUT, POST, and DELETE requests from all sources.

Note: This configuration can be insecure.

<CORSConfiguration>   
<CORSRule>   
    <ID>Allow   
    everything</ID>   
    <AllowedOrigin>\*</AllowedOrigin>   
    <AllowedMethod>GET</AllowedMethod>   
    <AllowedMethod>HEAD</AllowedMethod>   
    <AllowedMethod>PUT</AllowedMethod>   
    <AllowedMethod>POST</AllowedMethod>   
    <AllowedMethod>DELETE</AllowedMethod>   
    <AllowedHeader>\*</AllowedHeader>   
    <MaxAgeSeconds>30</MaxAgeSeconds>   
</CORSRule>   
</CORSConfiguration>

After the configuration is completed, apply it to the bucket with the following command:

s3cmd setcors cors.xml s3://<bucket_name> 

Add objects to a bucket

The example shows how to add two objects (test_file1 and test_file2) to the s3test bucket.

var params1 = {   Bucket: s3test, Key: 'test_file1',    Body: "test"  }; var params2 = {   Bucket: s3test, Key: 'test_file2',    Body: "test"  };  var request = s3.putObject(params1);  request.send(function (err, data) {    if (err) console.log("Error:", err.code, err.message);    else console.log(data);  });  var request = s3.putObject(params2);  request.send(function (err, data) {    if (err) console.log("Error:", err.code, err.message);    else console.log(data);  });

Get a list of objects

The example shows how to get a list of files in the test_2 bucket.

params = {   
    Bucket: "test_2"   
   };   
s3.listObjects(params, function(err, data) {   
    if (err) return;   
      data.Contents.map(function(info){   
        var ul = document.getElementById("list");   
        var li = document.createElement("li");   
        li.innerText = info.Key + " " + info.LastModified;   
        ul.append(li);   
      });   
  });

Was this article helpful?

Not a Gcore user yet?

Check out our Storage

Go to the product page