| 1 | // Plain async Lambda handler (deployed with `isExternal: true` — no Effect |
| 2 | // runtime in the bundle) that exercises an EFS mount at /mnt/test. |
| 3 | import { promises as fs } from "node:fs"; |
| 4 | |
| 5 | const FILE = "/mnt/test/persist.txt"; |
| 6 | |
| 7 | export const handler = async (event: { |
| 8 | rawPath?: string; |
| 9 | requestContext?: { http?: { path?: string } }; |
| 10 | queryStringParameters?: Record<string, string>; |
| 11 | }) => { |
| 12 | const path = event.rawPath ?? event.requestContext?.http?.path ?? "/"; |
| 13 | try { |
| 14 | if (path === "/write") { |
| 15 | const content = event.queryStringParameters?.content ?? "hello-from-efs"; |
| 16 | await fs.writeFile(FILE, content, "utf8"); |
| 17 | return { |
| 18 | statusCode: 200, |
| 19 | headers: { "content-type": "application/json" }, |
| 20 | body: JSON.stringify({ written: content }), |
| 21 | }; |
| 22 | } |
| 23 | if (path === "/read") { |
| 24 | const content = await fs.readFile(FILE, "utf8"); |
| 25 | return { |
| 26 | statusCode: 200, |
| 27 | headers: { "content-type": "application/json" }, |
| 28 | body: JSON.stringify({ |
| 29 | content, |
| 30 | marker: process.env.DEPLOY_MARKER ?? "unset", |
| 31 | }), |
| 32 | }; |
| 33 | } |
| 34 | if (path === "/mount") { |
| 35 | const entries = await fs.readdir("/mnt/test"); |
| 36 | return { |
| 37 | statusCode: 200, |
| 38 | headers: { "content-type": "application/json" }, |
| 39 | body: JSON.stringify({ mounted: true, entries }), |
| 40 | }; |
| 41 | } |
| 42 | return { statusCode: 200, body: "ok" }; |
| 43 | } catch (error) { |
| 44 | return { |
| 45 | statusCode: 500, |
| 46 | headers: { "content-type": "application/json" }, |
| 47 | body: JSON.stringify({ error: String(error) }), |
| 48 | }; |
| 49 | } |
| 50 | }; |
| 51 | |
| 52 | export default handler; |