From 45798cd458ec98fdb836de12bd1bc1b60ff408e8 Mon Sep 17 00:00:00 2001 From: Kanji Tanaka Date: Sat, 26 Nov 2022 12:42:23 +0900 Subject: [PATCH] Fix create bucket method using v3 way --- serverless-s3-local/index.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/serverless-s3-local/index.js b/serverless-s3-local/index.js index 46db7be0..bd61d7b2 100644 --- a/serverless-s3-local/index.js +++ b/serverless-s3-local/index.js @@ -322,11 +322,13 @@ class ServerlessS3Local { return Promise.resolve([]); } + const { CreateBucketCommand } = require("@aws-sdk/client-s3") const s3Client = this.getClient(); return Promise.all( buckets.map((Bucket) => { this.serverless.cli.log(`creating bucket: ${Bucket}`); - return s3Client.createBucket({ Bucket }).promise(); + const command = new CreateBucketCommand({ Bucket }); + return s3Client.send(command); }) ).catch(() => ({})); } @@ -347,14 +349,14 @@ class ServerlessS3Local { } getClient() { - const { S3 } = require("@aws-sdk/client-s3"); - return new S3({ - s3ForcePathStyle: true, - endpoint: new AWS.Endpoint( - `http://${this.options.host}:${this.options.port}` - ), - accessKeyId: this.options.accessKeyId, - secretAccessKey: this.options.secretAccessKey, + const { S3Client } = require("@aws-sdk/client-s3"); + return new S3Client({ + forcePathStyle: true, + endpoint: `http://${this.options.host}:${this.options.port}`, + credentials: { + accessKeyId: this.options.accessKeyId, + secretAccessKey: this.options.secretAccessKey, + }, }); }