@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 37 lines 1.36 KB
Raw
1 import * as Lambda from "@alchemy.run/aws/Lambda";
2 import * as GCP from "@alchemy.run/gcp";
3 import * as Cause from "effect/Cause";
4 import * as Duration from "effect/Duration";
5 import * as Effect from "effect/Effect";
6 import * as HttpServerResponse from "effect/http/HttpServerResponse";
7 import path from "pathe";
8
9 /** Topic the Lambda publishes to. */
10 export const Events = GCP.PubSub.Topic("FederatedEvents", {});
11
12 export class FederatedLambda extends Lambda.Function<Lambda.Function>()("FederatedLambda") {}
13
14 /**
15 * An AWS Lambda publishing to a GCP topic. It runs as an IAM role, so it
16 * reaches Pub/Sub by exchanging its AWS identity for a service account's
17 * token, not with a service account key. Deployed from
18 * {@link ../GCPBindings.test.ts}.
19 */
20 export default FederatedLambda.make(
21 {
22 main: path.resolve(import.meta.dirname, "aws-host.ts"),
23 functionUrl: true,
24 timeout: Duration.seconds(30),
25 },
26 Effect.gen(function* () {
27 const publish = yield* GCP.PubSub.Publish(yield* Events);
28 return {
29 fetch: publish({ body: { messages: [{ data: btoa("hello from lambda") }] } }).pipe(
30 Effect.flatMap((response) => HttpServerResponse.json(response)),
31 Effect.catchCause((cause) =>
32 HttpServerResponse.json({ error: Cause.pretty(cause) }, { status: 500 }),
33 ),
34 ),
35 };
36 }).pipe(Effect.provide(GCP.PubSub.PublishHttp)),
37 );