S3 Operations

This page contains several code snipets to help set up S3 operations.

AWS SDK

These are the items needed in order to connect to a AWS object storage server

ItemValueDescription
endPointhttps://alpha-s3-storage.mantle.technology:9000URL to object storage service.
accessKeyId{{ACCESS_KEY}}Access key used to log into Mantle Console
secretAccessKey{{SECRET_KEY}}Secret key used to log in Mantle Console

Let's take a look at some simple functions.

List Buckets

const AWS = require('aws-sdk');

async function AWSListBucket() {
    const s3 = new AWS.S3({
    accessKeyId: "{{ACESS_KEY}}",
    secretAccessKey: "{{SECRET_KEY}}",
    endpoint:"https://alpha-s3-storage.mantle.technology:9000"
    });
    s3.listBuckets(function(err, data){
        if (err) {
          console.log("Error", err);
        } else {
          console.log("Success", data.Buckets);
        }
    })
}

In this example, we have a simple function that calls AWS S3 to return a list of the buckets already existing. If the call succedes we log the list of buckets, otherwise we log the error.

Just replace {{ACCESS_KEY}} with you actual acces key and {{SECRET_KEY}} with you actual secret key

List Objects in Bucket

const AWS = require('aws-sdk');

async function AWSListMantleObjects() {
    const s3 = new AWS.S3({
    accessKeyId: "XXXXXX",
    secretAccessKey: "XXXXXXXX",
    endpoint:"https://alpha-s3-storage.mantle.technology:9000",
    s3ForcePathStyle: true,
    bucketName:"mantle"
    });

    var bucketParams = {
        Bucket : bucketName,
    };

    s3.listObjectsV2(bucketParams ,function(err, data){
        console.log(this)
        if (err) {
          console.log("Error", err);
        } else {
          console.log("Success", data.Buckets);
        }
    })
}

In this example, we have a simple function that calls AWS object storage server to return a list of the objects in a bucket named: mantle. If the call succedes we log the list of objcets, otherwise we log the error.

Just replace {{ACCESS_KEY}} with you actual acces key and {{SECRET_KEY}} with you actual secret key

🚧

Careful

When using certains AWS version the boolean s3ForcePathStyle: true otherwise the bucket is represented as a sub domain instead of a path.

Let's take a bucket named test for example:

s3ForcePathStyle: false ==> http://test.alpha-s3-storage.mantle.technology:9000/

s3ForcePathStyle: true ==> http://alpha-s3-storage.mantle.technology:9000/test

More info on AWS S3 here

MinIO SDK

These are the items needed in order to connect to a MinIO object storage server

ItemvalueDescription
endPointhttps://alpha-s3-storage.mantle.technologyURL to object storage service.
port9000TCP/IP port number. This input is optional. Default value set to 80 for HTTP and 443 for HTTPs
useSSLtrueSet this value to 'true' to enable secure (HTTPS) access
accessKey{{ACCESS_KEY}}Access key used to log into Mantle Console
secretKey{{SECRET_KEY}}Secret key used to log in Mantle Console

Let's take a look at some simple functions.

List Buckets

var Minio = require('minio')

var minioClient = new Minio.Client({
    endPoint: 'https://alpha-s3-storage.mantle.technology',
    port: 9000,
    useSSL: true,
    accessKey: '{{ACCESS_KEY}}',
    secretKey: '{{SECRET_KEY}}'
});

minioClient.listBuckets(function(err, buckets) {
  if (err) {
    return console.log(err)
  }
  console.log('buckets :', buckets)
})

In this example, we have a simple function that calls MinIO object storage server to return a list of the buckets already existing. If the call succedes we log the list of buckets, otherwise we log the error.

Just replace {{ACCESS_KEY}} with you actual acces key and {{SECRET_KEY}} with you actual secret key

List Objects in Bucket

var Minio = require('minio')

var minioClient = new Minio.Client({
    endPoint: 'https://alpha-s3-storage.mantle.technology',
    port: 9000,
    useSSL: true,
    accessKey: '{{ACCESS_KEY}}',
    secretKey: '{{SECRET_KEY}}'
});

var data = []
var stream = minioClient.listObjects('mantle','', true)
stream.on('data', function(obj) { data.push(obj) } )
stream.on("end", function (obj) { console.log(data) })
stream.on('error', function(err) { console.log(err) } )

In this example, we have a simple function that calls MinIO object storage server to return a list of the objects in a bucket named: mantle. If the call succedes we log the list of objcets, otherwise we log the error.

Just replace {{ACCESS_KEY}} with you actual acces key and {{SECRET_KEY}} with you actual secret key

More info on MinIO here