Skip to content

Commit 7eaabe0

Browse files
committed
update documentation with sdk v3 commands
1 parent 585fd46 commit 7eaabe0

File tree

2 files changed

+57
-48
lines changed

2 files changed

+57
-48
lines changed

docs/CLIENTS.rst

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,25 @@ JavaScript
124124

125125
.. code:: javascript
126126
127-
const AWS = require('aws-sdk');
128-
129-
const s3 = new AWS.S3({
130-
accessKeyId: 'accessKey1',
131-
secretAccessKey: 'verySecretKey1',
132-
endpoint: 'localhost:8000',
133-
sslEnabled: false,
134-
s3ForcePathStyle: true,
127+
const { S3Client, ListBucketsCommand } = require('@aws-sdk/client-s3');
128+
129+
const s3 = new S3Client({
130+
region: 'us-east-1',
131+
endpoint: 'http://localhost:8000',
132+
forcePathStyle: true,
133+
credentials: {
134+
accessKeyId: 'accessKey1',
135+
secretAccessKey: 'verySecretKey1',
136+
},
135137
});
136138
139+
async function listBuckets() {
140+
const result = await s3.send(new ListBucketsCommand({}));
141+
console.log(result.Buckets);
142+
}
143+
144+
listBuckets().catch(console.error);
145+
137146
JAVA
138147
~~~~
139148

docs/GETTING_STARTED.rst

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,13 @@ if you are using the AWS SDK for JavaScript, instantiate your client like this:
247247

248248
.. code:: js
249249
250-
const s3 = new aws.S3({
251-
endpoint: 'http://127.0.0.1:8000',
252-
s3ForcePathStyle: true,
253-
});
250+
const { S3Client } = require('@aws-sdk/client-s3');
251+
252+
const s3 = new S3Client({
253+
endpoint: 'http://127.0.0.1:8000',
254+
forcePathStyle: true,
255+
region: 'us-east-1',
256+
});
254257
255258
Setting Your Own Access and Secret Key Pairs
256259
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -379,47 +382,44 @@ SSL certificates.
379382
Test the Config
380383
^^^^^^^^^^^^^^^
381384

382-
If aws-sdk is not installed, run ``$> yarn install aws-sdk``.
385+
If the AWS SDK for JavaScript v3 packages are not installed locally, run ``$> yarn add @aws-sdk/client-s3 @aws-sdk/node-http-handler``.
383386

384387
Paste the following script into a file named "test.js":
385388

386389
.. code:: js
387390
388-
const AWS = require('aws-sdk');
389-
const fs = require('fs');
390-
const https = require('https');
391-
392-
const httpOptions = {
393-
agent: new https.Agent({
394-
// path on your host of the self-signed certificate
395-
ca: fs.readFileSync('./ca.crt', 'ascii'),
396-
}),
397-
};
398-
399-
const s3 = new AWS.S3({
400-
httpOptions,
401-
accessKeyId: 'accessKey1',
402-
secretAccessKey: 'verySecretKey1',
403-
// The endpoint must be s3.scality.test, else SSL will not work
404-
endpoint: 'https://s3.scality.test:8000',
405-
sslEnabled: true,
406-
// With this setup, you must use path-style bucket access
407-
s3ForcePathStyle: true,
408-
});
409-
410-
const bucket = 'cocoriko';
411-
412-
s3.createBucket({ Bucket: bucket }, err => {
413-
if (err) {
414-
return console.log('err createBucket', err);
415-
}
416-
return s3.deleteBucket({ Bucket: bucket }, err => {
417-
if (err) {
418-
return console.log('err deleteBucket', err);
419-
}
420-
return console.log('SSL is cool!');
421-
});
422-
});
391+
const { S3Client, CreateBucketCommand, DeleteBucketCommand } = require('@aws-sdk/client-s3');
392+
const { NodeHttpHandler } = require('@aws-sdk/node-http-handler');
393+
const fs = require('fs');
394+
const https = require('https');
395+
396+
const httpsAgent = new https.Agent({
397+
// path on your host of the self-signed certificate
398+
ca: fs.readFileSync('./ca.crt', 'ascii'),
399+
});
400+
401+
const s3 = new S3Client({
402+
requestHandler: new NodeHttpHandler({ httpsAgent }),
403+
credentials: {
404+
accessKeyId: 'accessKey1',
405+
secretAccessKey: 'verySecretKey1',
406+
},
407+
endpoint: 'https://s3.scality.test:8000',
408+
forcePathStyle: true,
409+
region: 'us-east-1',
410+
});
411+
412+
const bucket = 'cocoriko';
413+
414+
(async () => {
415+
try {
416+
await s3.send(new CreateBucketCommand({ Bucket: bucket }));
417+
await s3.send(new DeleteBucketCommand({ Bucket: bucket }));
418+
console.log('SSL is cool!');
419+
} catch (err) {
420+
console.error('error running sample', err);
421+
}
422+
})();
423423
424424
Now run this script with:
425425

0 commit comments

Comments
 (0)