Skip to main content

How to use AWS SDK for JavaScript with Stook?

The storage service of Medianova is Stook uses the AWS SDK.

For our customers to use this SDK with Stook, we have created a sample.js below.

This example shows how to;

  • set credentials up,

  • create a bucket

  • upload a file.

Install SDK

CODE
var AWS = require('aws-sdk');

Create S3 User

CODE
var config = {       s3ForcePathStyle: true,}var credentials = new AWS.SharedIniFileCredentials({profile: 'medianova'});AWS.config.credentials = credentials;AWS.config.update(config);var ep = new AWS.Endpoint('*******.mncdn.com');var s3 = new AWS.S3({endpoint: ep});

Create Bucket and Upload Something

CODE
var bucketName = 'medianovatest';var keyName = 'hello_world.txt';s3.createBucket({Bucket: bucketName}, function() {       var params = {Bucket: bucketName, Key: keyName, Body: 'Hello World!'};       s3.putObject(params, function(err, data) {               if (err)                       console.log(err)               else                       console.log("Successfully uploaded data to " + bucketName + "/" + keyName);       });});

Config.json’s Contents

CODE
medianova@vm:~/aws-nodejs-sample$ more config.json -"accessKeyId": your_medianova_access_key,-"secretAccessKey": your_medianova_secret_key-"region": "us-east-1" }

You can also add different profile information with the credentials file under the “~ / .aws” directory.

aws_access_key_id = your_medianova_access_key
aws_secret_access_key = your_medianova_secret_key

In this case, you will not need 2 lines in the script given above.

CODE
var credentials = new AWS.SharedIniFileCredentials({profile: 'medianova'});AWS.config.credentials = credentials;Then run the same script as follows.wasabi@vm:~/aws-nodejs-sample$ AWS_PROFILE=medianova node sample.jsSuccessfully uploaded data to node-sdk-sample-38cb5413-29c2-46f5-ab2d-4ac4d553f929/hello_world.txt

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.