@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 58 lines 2.03 KB
Raw
1 import * as Lambda from "@alchemy.run/aws/Lambda";
2 import * as OAM from "@alchemy.run/aws/OAM";
3 import * as Duration from "effect/Duration";
4 import * as Effect from "effect/Effect";
5 import { HttpServerRequest } from "effect/http/HttpServerRequest";
6 import * as HttpServerResponse from "effect/http/HttpServerResponse";
7 import path from "pathe";
8
9 const main = path.resolve(import.meta.dirname, "handler.ts");
10
11 export class OamTestFunction extends Lambda.Function<Lambda.Function>()("OamTestFunction") {}
12
13 export default OamTestFunction.make(
14 {
15 main,
16 functionUrl: true,
17 timeout: Duration.seconds(30),
18 },
19 Effect.gen(function* () {
20 // The monitoring-account sink the binding is bound to. Nothing ever
21 // links to it (OAM rejects same-account links), so ListAttachedLinks
22 // legitimately returns an empty item list — which still proves the IAM
23 // grant and the SinkIdentifier injection end-to-end.
24 const sink = yield* OAM.Sink("BindingSink");
25
26 const listAttachedLinks = yield* OAM.ListAttachedLinks(sink);
27
28 const bound = { listAttachedLinks };
29
30 return {
31 fetch: Effect.gen(function* () {
32 const request = yield* HttpServerRequest;
33 const url = new URL(request.originalUrl);
34 const pathname = url.pathname;
35
36 if (request.method === "GET" && pathname === "/bindings") {
37 return yield* HttpServerResponse.json({
38 bound: Object.keys(bound),
39 });
40 }
41
42 // Sink-scoped list: the SinkIdentifier is injected from the binding.
43 if (request.method === "GET" && pathname === "/attached-links") {
44 const { Items } = yield* listAttachedLinks();
45 return yield* HttpServerResponse.json({
46 count: Items.length,
47 linkArns: Items.map((item) => item.LinkArn),
48 });
49 }
50
51 return yield* HttpServerResponse.json(
52 { error: "Not found", method: request.method, pathname },
53 { status: 404 },
54 );
55 }).pipe(Effect.orDie),
56 };
57 }).pipe(Effect.provide(OAM.ListAttachedLinksHttp)),
58 );