The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import * as Output from "alchemy/Output"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | |
| 5 | /** |
| 6 | * In-stack networking for a real MWAA environment. CreateEnvironment rejects |
| 7 | * public subnets (`ValidationException: The subnets must be private.`) and the |
| 8 | * environment needs outbound egress, so this builds a VPC with two private |
| 9 | * subnets in distinct AZs (plus their public counterparts), an Internet |
| 10 | * Gateway, and ONE shared NAT gateway, and a security group with the |
| 11 | * self-referencing all-traffic ingress rule MWAA components need to reach each |
| 12 | * other. |
| 13 | * |
| 14 | * The returned IDs carry dependencies on the NAT route / route-table |
| 15 | * associations and on the self-referencing rule, so the environment is only |
| 16 | * created once egress is wired — and is torn down before any of them. |
| 17 | */ |
| 18 | export const MwaaNetwork = (id: string, cidrBlock: string) => |
| 19 | Effect.gen(function* () { |
| 20 | const network = yield* AWS.EC2.Network(id, { |
| 21 | cidrBlock, |
| 22 | availabilityZones: 2, |
| 23 | nat: "single", |
| 24 | }); |
| 25 | |
| 26 | const egressRoute = network.privateRoutes[0]; |
| 27 | const subnetIds = network.privateSubnets.map((subnet, index) => |
| 28 | Output.all( |
| 29 | subnet.subnetId, |
| 30 | network.privateRouteAssociations[index].associationId, |
| 31 | egressRoute.routeTableId, |
| 32 | ).pipe(Output.map(([subnetId]) => subnetId)), |
| 33 | ); |
| 34 | |
| 35 | const securityGroup = yield* AWS.EC2.SecurityGroup(`${id}SecurityGroup`, { |
| 36 | vpcId: network.vpcId, |
| 37 | description: "MWAA environment", |
| 38 | }); |
| 39 | const selfIngress = yield* AWS.EC2.SecurityGroupRule(`${id}SelfIngress`, { |
| 40 | group: securityGroup, |
| 41 | type: "ingress", |
| 42 | ipProtocol: "-1", |
| 43 | referencedGroupId: securityGroup.groupId, |
| 44 | description: "MWAA components talk to each other", |
| 45 | }); |
| 46 | |
| 47 | return { subnetIds, securityGroupIds: [selfIngress.groupId] }; |
| 48 | }); |