Skip to content

Cluster.AWS reference

Source: packages/effect-cluster/src/AWS/CloudFrontGateway.ts

Serve a pool’s gateway over HTTPS on a *.cloudfront.net name, without a domain of your own: a CloudFront distribution reaches an internal load balancer through a VPC origin, so nothing on the internet reaches the load balancer itself.

CloudFrontGateway: Choosing a CloudFront gateway

Section titled “CloudFrontGateway: Choosing a CloudFront gateway”
export const Default = ClusterAWS.EcsPool("Default", {
gateway: ClusterAWS.CloudFrontGateway(),
}).pipe(Layer.provide(Database));

Source: packages/effect-cluster/src/AWS/Database.ts

The database an Effect Cluster coordinates through, on AWS, as a Cluster.Database Layer: Postgres on RDS, in a VPC of its own or the one you give it, which the runners join. Every runner joins one security group, which reaches the database and the other runners on the runner port; nothing else does.

Postgres for the cluster

export const Database = ClusterAWS.Database("Cluster");

A larger instance with a standby

export const Database = ClusterAWS.Database("Cluster", {
instanceClass: "db.m7g.large",
multiAZ: true,
});

Give the database a network by id: the database, the runners and their gateways run in its subnetIds. Runners take public IPs unless assignPublicIp is false, as in private subnets behind a NAT gateway.

A VPC nobody manages

const vpc = EC2.Vpc.lookup({ name: "shared" });
const a = EC2.Subnet.lookup({ name: "private-a" });
const b = EC2.Subnet.lookup({ name: "private-b" });
export const Database = ClusterAWS.Database("Cluster", {
network: {
vpcId: vpc.vpcId,
subnetIds: [a.subnetId, b.subnetId],
cidrBlock: vpc.cidrBlock,
assignPublicIp: false,
},
});

A declaration or another stack’s resource is an Effect: yield it in an Effect that returns the network.

A network declared in the same stack

export const AppNetwork = EC2.Network("App", {
cidrBlock: "10.42.0.0/16",
nat: "single",
});
export const Database = ClusterAWS.Database("Cluster", {
network: Effect.gen(function* () {
const network = yield* AppNetwork;
return {
vpcId: network.vpcId,
subnetIds: network.privateSubnetIds,
publicSubnetIds: network.publicSubnetIds,
cidrBlock: network.vpc.cidrBlock,
assignPublicIp: false,
};
}),
});

A VPC another stack owns

export const Database = ClusterAWS.Database("Cluster", {
network: Effect.gen(function* () {
const vpc = yield* EC2.Vpc.ref("AppVpc", { stack: "network" });
const a = yield* EC2.Subnet.ref("PrivateSubnetA", { stack: "network" });
const b = yield* EC2.Subnet.ref("PrivateSubnetB", { stack: "network" });
return {
vpcId: vpc.vpcId,
subnetIds: [a.subnetId, b.subnetId],
cidrBlock: vpc.cidrBlock,
assignPublicIp: false,
};
}),
});

Source: packages/effect-cluster/src/AWS/EcsPool.ts

Run a pool of Effect Cluster runners on ECS Fargate: an ECS service whose tasks host every class given this pool, in the database’s VPC, behind the gateway its callers reach it through. With a database in no VPC (Cluster.Database.fromUrl), give the pool its network.

Runners reach each other and the database through the cluster’s runner security group; the gateway’s load balancer only reaches the gateway, which checks every call’s token.

The database URL, the gateway token, and every other secret bound into the runners’ environment are kept in Secrets Manager secrets of the pool’s own. The task definition only names them, and only the tasks’ execution role may read them.

Two runners on Fargate

export const Database = ClusterAWS.Database("Cluster");
export const Default = ClusterAWS.EcsPool("Default", { replicas: 2 }).pipe(
Layer.provide(Database),
);

Larger Graviton runners

export const Default = ClusterAWS.EcsPool("Default", {
cpu: 2048,
memory: 4096,
architecture: "ARM64",
}).pipe(Layer.provide(Database));

Without a gateway, an internet-facing load balancer serves plain HTTP.

HTTPS on your domain

export const Default = ClusterAWS.EcsPool("Default", {
gateway: ClusterAWS.LoadBalancerGateway({ domain: "cluster.example.com" }),
}).pipe(Layer.provide(Database));

HTTPS without a domain, through CloudFront

export const Default = ClusterAWS.EcsPool("Default", {
gateway: ClusterAWS.CloudFrontGateway(),
}).pipe(Layer.provide(Database));

Only callers inside the VPC

export const Default = ClusterAWS.EcsPool("Default", {
gateway: ClusterAWS.LoadBalancerGateway({ scheme: "internal" }),
}).pipe(Layer.provide(Database));

Runners join the securityGroupId, which must reach the database; without one, the pool creates a group the database must admit.

Runners in a VPC by id

export const Database = Cluster.Database.fromUrl(Config.redacted("DATABASE_URL"));
export const Default = ClusterAWS.EcsPool("Default", {
network: {
vpcId: "vpc-0123456789abcdef0",
subnetIds: ["subnet-0123456789abcdef0", "subnet-0fedcba9876543210"],
securityGroupId: "sg-0123456789abcdef0",
},
}).pipe(Layer.provide(Database));

Runners in a VPC another stack owns

export const Database = Cluster.Database.fromUrl(Config.redacted("DATABASE_URL"));
export const Default = ClusterAWS.EcsPool("Default", {
network: Effect.gen(function* () {
const vpc = yield* EC2.Vpc.ref("AppVpc", { stack: "network" });
const a = yield* EC2.Subnet.ref("PrivateSubnetA", { stack: "network" });
const b = yield* EC2.Subnet.ref("PrivateSubnetB", { stack: "network" });
return {
vpcId: vpc.vpcId,
subnetIds: [a.subnetId, b.subnetId],
assignPublicIp: false,
};
}),
}).pipe(Layer.provide(Database));

Source: packages/effect-cluster/src/AWS/LoadBalancerGateway.ts

Serve a pool’s gateway from an Application Load Balancer. Calls may stay open for up to an hour, the load balancer’s idle timeout.

LoadBalancerGateway: Choosing a load balancer gateway

Section titled “LoadBalancerGateway: Choosing a load balancer gateway”

HTTPS on your domain

export const Default = ClusterAWS.EcsPool("Default", {
gateway: ClusterAWS.LoadBalancerGateway({ domain: "cluster.example.com" }),
}).pipe(Layer.provide(Database));

Only callers inside the VPC

export const Default = ClusterAWS.EcsPool("Default", {
gateway: ClusterAWS.LoadBalancerGateway({ scheme: "internal" }),
}).pipe(Layer.provide(Database));