Skip to content

Commit

Permalink
✨ Expose ERPC on the http port
Browse files Browse the repository at this point in the history
  • Loading branch information
KONFeature committed Jul 31, 2024
1 parent 3b3df97 commit 343cb2e
Show file tree
Hide file tree
Showing 6 changed files with 390 additions and 334 deletions.
123 changes: 65 additions & 58 deletions iac/Indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import { Cluster, type ICluster } from "aws-cdk-lib/aws-ecs";
import {
ApplicationLoadBalancer,
ApplicationProtocol,
ApplicationTargetGroup,
ListenerAction,
ListenerCondition,
} from "aws-cdk-lib/aws-elasticloadbalancingv2";
import { Duration } from "aws-cdk-lib/core";
import {
Expand Down Expand Up @@ -66,73 +69,77 @@ export function IndexerStack({ app, stack }: StackContext) {
internetFacing: true,
});

// Allow connections to the given ports
alb.connections.allowTo(indexerFaragateService, Port.tcp(80));
// Allow connections to the applications ports
alb.connections.allowTo(indexerFaragateService, Port.tcp(42069));
alb.connections.allowTo(erpcFargateService, Port.tcp(8080));
alb.connections.allowTo(erpcFargateService, Port.tcp(4001));

// Add the indexer service to the ALB
const indexerListener = alb.addListener("IndexerListener", {
// Create the listener on port 80
const httpListener = alb.addListener("HttpListener", {
port: 80,
});
indexerListener.addTargets("IndexerTarget", {
port: 80,
targets: [indexerFaragateService],
deregistrationDelay: Duration.seconds(30),
healthCheck: {
path: "/health",
interval: Duration.seconds(20),
healthyThresholdCount: 2,
unhealthyThresholdCount: 5,
healthyHttpCodes: "200-299",
},
});
indexerListener.connections.allowInternally(Port.tcp(80));
indexerListener.connections.allowFrom(alb.connections, Port.tcp(80));
httpListener.connections.allowInternally(Port.tcp(4001));
httpListener.connections.allowInternally(Port.tcp(8080));
httpListener.connections.allowInternally(Port.tcp(42069));

// todo: add erpc service to the ALB
// Add the listener on port 8080 for the rpc
const erpcListener = alb.addListener("ErpcListener", {
port: 8080,
protocol: ApplicationProtocol.HTTP,
// Create our erpc target group on port 8080 and bind it to the http listener
const erpcTargetGroup = new ApplicationTargetGroup(
stack,
"ErpcTargetGroup",
{
vpc: vpc,
port: 8080,
protocol: ApplicationProtocol.HTTP,
targets: [erpcFargateService],
deregistrationDelay: Duration.seconds(30),
healthCheck: {
path: "/",
port: "4001",
interval: Duration.seconds(30),
healthyThresholdCount: 2,
unhealthyThresholdCount: 5,
healthyHttpCodes: "200",
},
}
);
httpListener.addAction("ErpcForwardAction", {
action: ListenerAction.forward([erpcTargetGroup]),
});
erpcListener.addTargets("ErpcTarget", {
port: 8080,
protocol: ApplicationProtocol.HTTP,
targets: [erpcFargateService],
deregistrationDelay: Duration.seconds(30),
healthCheck: {
path: "/",
port: "4001",
interval: Duration.seconds(30),
healthyThresholdCount: 2,
unhealthyThresholdCount: 5,
healthyHttpCodes: "200",
},
httpListener.addTargetGroups("ErpcTarget", {
targetGroups: [erpcTargetGroup],
priority: 10,
conditions: [ListenerCondition.pathPatterns(["/main-rpc/*"])],
});
const erpcMetricsListener = alb.addListener("ErpcMetricsListener", {
port: 4001,
protocol: ApplicationProtocol.HTTP,

// Add the indexer service to the ALB on bind it to the port 42069
const indexerTargetGroup = new ApplicationTargetGroup(
stack,
"IndexerTargetGroup",
{
vpc: vpc,
port: 42069,
protocol: ApplicationProtocol.HTTP,
targets: [indexerFaragateService],
deregistrationDelay: Duration.seconds(30),
healthCheck: {
path: "/health",
interval: Duration.seconds(20),
healthyThresholdCount: 2,
unhealthyThresholdCount: 5,
healthyHttpCodes: "200-299",
},
}
);
httpListener.addAction("IndexerForwardAction", {
action: ListenerAction.forward([indexerTargetGroup]),
});
erpcMetricsListener.addTargets("ErpcMetricsTarget", {
port: 4001,
protocol: ApplicationProtocol.HTTP,
targets: [erpcFargateService],
deregistrationDelay: Duration.seconds(30),
healthCheck: {
path: "/",
port: "4001",
interval: Duration.seconds(30),
healthyThresholdCount: 2,
unhealthyThresholdCount: 5,
healthyHttpCodes: "200",
},
httpListener.addTargetGroups("IndexerTarget", {
targetGroups: [indexerTargetGroup],
priority: 20,
conditions: [ListenerCondition.pathPatterns(["/*"])],
});
erpcListener.connections.allowInternally(Port.tcp(4001));
erpcListener.connections.allowInternally(Port.tcp(8080));
erpcListener.connections.allowFrom(alb.connections, Port.tcp(8080));
erpcListener.connections.allowFrom(alb.connections, Port.tcp(4001));

// Create our CDN cache policy
const cachePolicy = new CachePolicy(this, "CachePolicy", {
queryStringBehavior: CacheQueryStringBehavior.all(),
headerBehavior: CacheHeaderBehavior.none(),
Expand Down Expand Up @@ -246,8 +253,8 @@ function addErpcService({
image: erpcImage,
secrets: cdkSecretsMap,
portMappings: [
{ containerPort: 8080, hostPort: 8080 },
{ containerPort: 4001, hostPort: 4001 },
{ containerPort: 8080 },
{ containerPort: 4001 },
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"devDependencies": {
"@biomejs/biome": "1.8.3",
"@types/aws-lambda": "8.10.138",
"@types/node": "^20.14.12",
"@types/node": "^22.0.0",
"aws-cdk-lib": "2.142.1",
"sst": "2.43.4",
"typescript": "^5.5.4"
Expand Down
4 changes: 1 addition & 3 deletions packages/erpc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ FROM ghcr.io/erpc/erpc:latest
# Copy the config
COPY erpc.yaml /root/erpc.yaml

EXPOSE 4000
EXPOSE 4001

# Run the server
CMD ["./erpc-server"]
4 changes: 1 addition & 3 deletions packages/erpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
"lint": "biome lint .",
"typecheck": "tsc"
},
"dependencies": {
},
"devDependencies": {
"@biomejs/biome": "1.8.3",
"@types/aws-lambda": "8.10.138",
"@types/node": "^20.14.9",
"@types/node": "^22.0.0",
"aws-cdk-lib": "2.142.1",
"sst": "2.43.4",
"typescript": "^5.3.2"
Expand Down
6 changes: 3 additions & 3 deletions packages/ponder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
"typecheck": "tsc"
},
"dependencies": {
"@ponder/core": "^0.5.3",
"hono": "^4.5.1",
"@ponder/core": "^0.5.5",
"hono": "^4.5.3",
"viem": "^1.21.4"
},
"devDependencies": {
"@biomejs/biome": "1.8.3",
"@types/aws-lambda": "8.10.138",
"@types/node": "^20.14.9",
"@types/node": "^22.0.0",
"aws-cdk-lib": "2.142.1",
"sst": "2.43.4",
"typescript": "^5.3.2"
Expand Down
Loading

0 comments on commit 343cb2e

Please sign in to comment.