The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as EKS from "@alchemy.run/aws/EKS"; |
| 2 | import * as Lambda from "@alchemy.run/aws/Lambda"; |
| 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 * as Layer from "effect/Layer"; |
| 8 | import path from "pathe"; |
| 9 | |
| 10 | const main = path.resolve(import.meta.dirname, "handler.ts"); |
| 11 | |
| 12 | export class EksTestFunction extends Lambda.Function<Lambda.Function>()("EksTestFunction") {} |
| 13 | |
| 14 | /** |
| 15 | * Account-level EKS bindings fixture. The cluster-scoped bindings |
| 16 | * (`DescribeCluster`, `ListNodegroups`, …) require a live EKS control plane |
| 17 | * (~10+ minutes to provision) and are exercised by the env-gated |
| 18 | * `ClusterBindings.test.ts` fixture instead. The five account-scoped |
| 19 | * discovery/catalog bindings need no cluster at all, so this fixture proves |
| 20 | * their init + IAM + runtime wiring ungated. |
| 21 | */ |
| 22 | export default EksTestFunction.make( |
| 23 | { |
| 24 | main, |
| 25 | functionUrl: true, |
| 26 | timeout: Duration.seconds(30), |
| 27 | }, |
| 28 | Effect.gen(function* () { |
| 29 | const listClusters = yield* EKS.ListClusters(); |
| 30 | const listAccessPolicies = yield* EKS.ListAccessPolicies(); |
| 31 | const describeClusterVersions = yield* EKS.DescribeClusterVersions(); |
| 32 | const describeAddonVersions = yield* EKS.DescribeAddonVersions(); |
| 33 | const describeAddonConfiguration = yield* EKS.DescribeAddonConfiguration(); |
| 34 | |
| 35 | const bound = { |
| 36 | listClusters, |
| 37 | listAccessPolicies, |
| 38 | describeClusterVersions, |
| 39 | describeAddonVersions, |
| 40 | describeAddonConfiguration, |
| 41 | }; |
| 42 | |
| 43 | return { |
| 44 | fetch: Effect.gen(function* () { |
| 45 | const request = yield* HttpServerRequest; |
| 46 | const url = new URL(request.originalUrl); |
| 47 | const pathname = url.pathname; |
| 48 | |
| 49 | if (request.method === "GET" && pathname === "/bindings") { |
| 50 | return yield* HttpServerResponse.json({ |
| 51 | bound: Object.keys(bound), |
| 52 | }); |
| 53 | } |
| 54 | |
| 55 | if (request.method === "GET" && pathname === "/clusters") { |
| 56 | const { clusters } = yield* listClusters(); |
| 57 | return yield* HttpServerResponse.json({ |
| 58 | count: (clusters ?? []).length, |
| 59 | }); |
| 60 | } |
| 61 | |
| 62 | if (request.method === "GET" && pathname === "/access-policies") { |
| 63 | const { accessPolicies } = yield* listAccessPolicies(); |
| 64 | return yield* HttpServerResponse.json({ |
| 65 | count: (accessPolicies ?? []).length, |
| 66 | names: (accessPolicies ?? []).map((policy) => policy.name), |
| 67 | }); |
| 68 | } |
| 69 | |
| 70 | if (request.method === "GET" && pathname === "/cluster-versions") { |
| 71 | const { clusterVersions } = yield* describeClusterVersions({ |
| 72 | defaultOnly: true, |
| 73 | }); |
| 74 | return yield* HttpServerResponse.json({ |
| 75 | count: (clusterVersions ?? []).length, |
| 76 | defaultVersion: clusterVersions?.[0]?.clusterVersion, |
| 77 | }); |
| 78 | } |
| 79 | |
| 80 | if (request.method === "GET" && pathname === "/addon-versions") { |
| 81 | const { addons } = yield* describeAddonVersions({ |
| 82 | addonName: "vpc-cni", |
| 83 | maxResults: 1, |
| 84 | }); |
| 85 | return yield* HttpServerResponse.json({ |
| 86 | count: (addons ?? []).length, |
| 87 | addonName: addons?.[0]?.addonName, |
| 88 | }); |
| 89 | } |
| 90 | |
| 91 | // Chains two catalog bindings: resolve a live vpc-cni version via |
| 92 | // DescribeAddonVersions, then fetch that version's configuration |
| 93 | // JSON schema via DescribeAddonConfiguration. |
| 94 | if (request.method === "GET" && pathname === "/addon-schema") { |
| 95 | const { addons } = yield* describeAddonVersions({ |
| 96 | addonName: "vpc-cni", |
| 97 | maxResults: 1, |
| 98 | }); |
| 99 | const addonVersion = addons?.[0]?.addonVersions?.[0]?.addonVersion; |
| 100 | if (!addonVersion) { |
| 101 | return yield* HttpServerResponse.json( |
| 102 | { error: "no vpc-cni addon version found" }, |
| 103 | { status: 404 }, |
| 104 | ); |
| 105 | } |
| 106 | const { configurationSchema } = yield* describeAddonConfiguration({ |
| 107 | addonName: "vpc-cni", |
| 108 | addonVersion, |
| 109 | }); |
| 110 | return yield* HttpServerResponse.json({ |
| 111 | addonVersion, |
| 112 | hasSchema: typeof configurationSchema === "string" && configurationSchema.length > 0, |
| 113 | }); |
| 114 | } |
| 115 | |
| 116 | return yield* HttpServerResponse.json( |
| 117 | { error: "Not found", method: request.method, pathname }, |
| 118 | { status: 404 }, |
| 119 | ); |
| 120 | }).pipe(Effect.orDie), |
| 121 | }; |
| 122 | }).pipe( |
| 123 | Effect.provide( |
| 124 | Layer.mergeAll( |
| 125 | EKS.ListClustersHttp, |
| 126 | EKS.ListAccessPoliciesHttp, |
| 127 | EKS.DescribeClusterVersionsHttp, |
| 128 | EKS.DescribeAddonVersionsHttp, |
| 129 | EKS.DescribeAddonConfigurationHttp, |
| 130 | ), |
| 131 | ), |
| 132 | ), |
| 133 | ); |