In this article, we will review the basics for using VPSA Object Storage with AWS S3 Javascript SDK. aws-sdk is the official AWS SDK for JavaScript.
The article refers to a node.js application.
Prerequisites
- Zadara VPSA Object Storage deployed in a location of your choice.
- AWS aws-sdk
- Node.JS development environment
Connectivity information
For Object Storage connectivity, it is required to gather the following information from the VPSA Object Storage management UI:
- VPSA Object Storage Endpoint
- VPSA Object Storage region.
- S3 API Access Key/Secret Key
From the VPSA Object Storage GUI, navigate to the User Information section (top right corner, by clicking the logged in username).
Example
The following example will:
- Configure the client details to work against the VPSA Object Storage.
- Upload a test Object to an existing bucket
- Download the test Object
var AWS = require('aws-sdk');
// VPSA Object Storage connection details - update the connectivity information.
var s3 = new AWS.S3({
accessKeyId: '<my access key>' ,
secretAccessKey: '<my secret key>' ,
endpoint: 'https://<my object storage endpoint>' ,
s3ForcePathStyle: true,
signatureVersion: 'v4',
region: 'us-east-1'
});
// putObject operation in existing container (bucket)
var params = {Bucket: 'test',
Key: 'testobject',
Body: 'Hello!'};
s3.putObject(params, function(err, data) {
if (err)
console.log(err)
else
console.log("Successfully uploaded data to:", params.Bucket, "/", params.Key);
});
// getObject operation. Get the recently created object and save it locally.
var params = {Bucket: params.Bucket, Key: params.Key};
var file = require('fs').createWriteStream('/tmp/myobject');
s3.getObject(params).
on('httpData', function(chunk) { file.write(chunk); }).
on('httpDone', function() { file.end(); }).
send();
Additional AWS S3 JavaScript SDK examples can be found in AWS S3 documentation.
Got a question? We love to help, send us a mail to support@zadarastorage.com