@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, 04:45 UTC

main
ts 38 lines 1.32 KB
Raw
1 import * as ec2 from "@distilled.cloud/aws/ec2";
2 import * as Effect from "effect/Effect";
3 import * as Layer from "effect/Layer";
4 import * as AWSBindings from "../AWSBindings.ts";
5 import { DescribeInstance } from "./DescribeInstance.ts";
6 import { type Instance } from "./Instance.ts";
7
8 // Bespoke (not the shared scaffold): `describeInstances` nests results under
9 // Reservations[].Instances[] and the client unwraps the single bound
10 // instance.
11 export const DescribeInstanceHttp = Layer.effect(
12 DescribeInstance,
13 Effect.gen(function* () {
14 const bind = yield* AWSBindings.Bind;
15 const describe = yield* AWSBindings.withCredentials(ec2.describeInstances);
16
17 return Effect.fn(function* (instance: Instance) {
18 const instanceId = yield* instance.instanceId;
19 if (!globalThis.__ALCHEMY_RUNTIME__) {
20 yield* bind`AWS.EC2.DescribeInstance(${instance})`({
21 policyStatements: [
22 {
23 Effect: "Allow",
24 Action: ["ec2:DescribeInstances"],
25 Resource: ["*"],
26 },
27 ],
28 });
29 }
30 return Effect.fn(`AWS.EC2.DescribeInstance(${instance.LogicalId})`)(function* () {
31 const result = yield* describe({
32 InstanceIds: [yield* instanceId],
33 });
34 return result.Reservations?.[0]?.Instances?.[0];
35 });
36 });
37 }),
38 );