# How to use AWS SDK for JavaScript with Stook?

You can use the [**AWS SDK for JavaScript**](https://docs.aws.amazon.com/sdk-for-javascript/) to connect your applications to **Medianova Stook Object Storage**. With the SDK, you can set credentials, create buckets, and upload files directly to Stook.

***

### Prerequisites

* Node.js installed on your system
* AWS SDK for JavaScript installed
* Medianova Stook credentials:
  * **Access Key**
  * **Secret Key**
  * **Endpoint**

***

### Installation

Install the AWS SDK for JavaScript:

```bash
npm install aws-sdk
```

***

### Example: Create Bucket and Upload File

`sample.js`

```javascript
var AWS = require('aws-sdk');

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});

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 Example

You can configure credentials in `config.json` or under `~/.aws/credentials`.

`config.json`:

```json
{
  "accessKeyId": "your_medianova_access_key",
  "secretAccessKey": "your_medianova_secret_key",
  "region": "us-east-1"
}
```

***

### Running the Script

If credentials are saved under `~/.aws/credentials` with profile `medianova`:

```bash
AWS_PROFILE=medianova node sample.js
```

Expected output:

```
Successfully uploaded data to node-sdk-sample-xxxx/hello_world.txt
```

***

### Troubleshooting / FAQ

* **Error:** Credentials not found
  * **Solution:** Ensure `config.json` or `~/.aws/credentials` contains valid keys.
* **Error:** Bucket already exists
  * **Solution:** Use a unique bucket name.
* **Error:** Connection issues
  * **Solution:** Verify endpoint URL and network connectivity.

***

### References

* [AWS SDK for JavaScript Documentation](https://docs.aws.amazon.com/sdk-for-javascript/)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://clients.medianova.com/products/object-storage-stook/integration-and-usage-guides/how-to-use-aws-sdk-for-javascript-with-stook.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
