@@ -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.
379382Test 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
384387Paste 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