webdino / lyceum-pokemon

ポケモン API を使った Nuxt+Express アプリ/サーバの開発演習
3 stars 28 forks source link

AWS JS SDKをつかったAWS S3のハンズオン #10

Closed knokmki612 closed 2 years ago

knokmki612 commented 2 years ago
diff --git a/express/index.js b/express/index.js
index 9968909..327954d 100644
--- a/express/index.js
+++ b/express/index.js
@@ -1,4 +1,5 @@
 import express from "express";
+import { S3Client, ListBucketsCommand } from "@aws-sdk/client-s3";

 const app = express();

@@ -6,4 +7,14 @@ app.get("/", (req, res) => {
   res.send("Hello World");
 });

+app.get("/buckets", async (req, res) => {
+  const client = new S3Client({});
+  try {
+    const buckets = await client.send(new ListBucketsCommand({}));
+    res.send(JSON.stringify(buckets));
+  } catch (err) {
+    res.status(500).send(err);
+  }
+});
+
 export default app;

によってS3バケット一覧を取得するAPIエンドポイントが追加できることを確認