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

main
ts 62 lines 2.12 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import * as Alchemy from "alchemy";
3 import * as Output from "alchemy/Output";
4 import * as Effect from "effect/Effect";
5 import * as Redacted from "effect/Redacted";
6
7 export const DB_USER = "app";
8 export const DB_NAME = "app";
9
10 /**
11 * A VPC with public subnets (for the tunnel connector) and private subnets
12 * (for Aurora). Nothing in the private subnets is reachable from the internet.
13 */
14 export const Network = AWS.EC2.Network("Network", {
15 cidrBlock: "10.63.0.0/16",
16 availabilityZones: 2,
17 });
18
19 /** Security group for the `cloudflared` connector — outbound only. */
20 export const ConnectorSecurityGroup = Effect.gen(function* () {
21 const network = yield* Network;
22 return yield* AWS.EC2.SecurityGroup("ConnectorSecurityGroup", {
23 vpcId: network.vpcId,
24 description: "cloudflared connector; no inbound connections",
25 });
26 });
27
28 /** Database password, generated once and kept in state. */
29 export const DbPassword = Alchemy.Random("DbPassword", { bytes: 24 });
30
31 /** Private Aurora PostgreSQL that only admits the connector. */
32 export const Database = Effect.gen(function* () {
33 const network = yield* Network;
34 const connector = yield* ConnectorSecurityGroup;
35 const password = yield* DbPassword;
36 const dbSecurityGroup = yield* AWS.EC2.SecurityGroup("DatabaseSecurityGroup", {
37 vpcId: network.vpcId,
38 description: "Postgres from the cloudflared connector only",
39 ingress: [
40 {
41 ipProtocol: "tcp",
42 fromPort: 5432,
43 toPort: 5432,
44 referencedGroupId: connector.groupId,
45 },
46 ],
47 });
48 const secret = yield* AWS.SecretsManager.Secret("DatabaseSecret", {
49 secretString: Output.map(password.text, (password) =>
50 Redacted.make(JSON.stringify({ username: DB_USER, password: Redacted.value(password) })),
51 ),
52 });
53 return yield* AWS.RDS.Aurora("Database", {
54 databaseName: DB_NAME,
55 engine: "aurora-postgresql",
56 engineVersion: "17.5",
57 subnetIds: network.privateSubnetIds,
58 securityGroupIds: [dbSecurityGroup.groupId],
59 secret: { resource: secret },
60 instance: { dbInstanceClass: "db.serverless", publiclyAccessible: false },
61 });
62 });