This repository has been archived on 2026-08-04. You can view files and clone it, but cannot push or open issues or pull requests.
seahaven-slack-bot/lib/constructs/socket-mode.ts
Adam Moussa ea173a0966 Enable Container Insights + RunningTaskCount alarm (NEEDS ADAM SIGN-OFF)
Enable Container Insights on the seahaven-socket-mode ECS cluster and add the
seahaven-socket-mode-running-tasks alarm (fires when running tasks < 1 against
desiredCount=1). RunningTaskCount is only published with Container Insights
enabled, which adds CloudWatch metric + log-ingestion cost.

This is isolated in its own commit so it can be dropped if the cost/config
change is declined — revert this commit (cluster containerInsightsV2 +
enableRunningTaskAlarm flag) and the rest of the alarm coverage is unaffected.
2026-06-17 13:57:48 -04:00

77 lines
2.6 KiB
TypeScript

import { Construct } from 'constructs';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import * as ecr_assets from 'aws-cdk-lib/aws-ecr-assets';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as logs from 'aws-cdk-lib/aws-logs';
import * as path from 'path';
export interface SocketModeProps {
vpc: ec2.IVpc;
processorLambda: lambda.IFunction;
appHomeLambda: lambda.IFunction;
}
export class SocketModeConstruct extends Construct {
public readonly cluster: ecs.Cluster;
public readonly service: ecs.FargateService;
constructor(scope: Construct, id: string, props: SocketModeProps) {
super(scope, id);
const appTokenSecret = secretsmanager.Secret.fromSecretNameV2(
this, 'AppTokenSecret', 'seahaven/slack/app-level-token',
);
const cluster = new ecs.Cluster(this, 'Cluster', {
clusterName: 'seahaven-socket-mode',
vpc: props.vpc,
// Container Insights publishes ECS/ContainerInsights metrics (incl.
// RunningTaskCount) needed for the task-count alarm. This adds CloudWatch
// metric + log cost — see PR body "NEEDS ADAM SIGN-OFF (cost/config)".
containerInsightsV2: ecs.ContainerInsights.ENABLED,
});
this.cluster = cluster;
const taskDef = new ecs.FargateTaskDefinition(this, 'TaskDef', {
memoryLimitMiB: 512,
cpu: 256,
runtimePlatform: {
cpuArchitecture: ecs.CpuArchitecture.ARM64,
operatingSystemFamily: ecs.OperatingSystemFamily.LINUX,
},
});
taskDef.addContainer('socket-mode', {
image: ecs.ContainerImage.fromAsset(
path.join(__dirname, '../../services/socket-mode'),
{ platform: ecr_assets.Platform.LINUX_ARM64 },
),
environment: {
APP_TOKEN_SECRET_ARN: appTokenSecret.secretArn,
PROCESSOR_FUNCTION_NAME: props.processorLambda.functionName,
APP_HOME_FUNCTION_NAME: props.appHomeLambda.functionName,
},
logging: ecs.LogDrivers.awsLogs({
streamPrefix: 'socket-mode',
logRetention: logs.RetentionDays.TWO_MONTHS,
}),
});
appTokenSecret.grantRead(taskDef.taskRole);
props.processorLambda.grantInvoke(taskDef.taskRole);
props.appHomeLambda.grantInvoke(taskDef.taskRole);
this.service = new ecs.FargateService(this, 'Service', {
serviceName: 'seahaven-socket-mode',
cluster,
taskDefinition: taskDef,
desiredCount: 1,
minHealthyPercent: 100,
maxHealthyPercent: 200,
assignPublicIp: false,
vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS },
});
}
}