Skip to content

Commit cb787b7

Browse files
refactor(compute): gate ECS construct on compute_type context
Replace comment toggle with proper context gate. ECS resources only synthesize when compute_type=ecs is passed. Default (agentcore) behavior unchanged. Closes #164 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent eb48cc7 commit cb787b7

2 files changed

Lines changed: 21 additions & 24 deletions

File tree

cdk/src/bootstrap/preflight/.gitkeep

Lines changed: 0 additions & 1 deletion
This file was deleted.

cdk/src/stacks/agent.ts

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ import * as bedrock from '@aws-cdk/aws-bedrock-alpha';
2323
import * as agentcoremixins from '@aws-cdk/mixins-preview/aws-bedrockagentcore';
2424
import { ArnFormat, AspectPriority, Aspects, Stack, StackProps, RemovalPolicy, CfnOutput, CfnResource, Duration, Fn, Lazy } from 'aws-cdk-lib';
2525
import * as ec2 from 'aws-cdk-lib/aws-ec2';
26-
// ecr_assets import is only needed when the ECS block below is uncommented
27-
// import * as ecr_assets from 'aws-cdk-lib/aws-ecr-assets';
26+
import * as ecr_assets from 'aws-cdk-lib/aws-ecr-assets';
2827
import * as iam from 'aws-cdk-lib/aws-iam';
2928
import * as logs from 'aws-cdk-lib/aws-logs';
3029
import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager';
@@ -38,12 +37,12 @@ import { Blueprint } from '../constructs/blueprint';
3837
import { CedarWasmLayer } from '../constructs/cedar-wasm-layer';
3938
import { ConcurrencyReconciler } from '../constructs/concurrency-reconciler';
4039
import { DnsFirewall } from '../constructs/dns-firewall';
40+
import { EcsAgentCluster } from '../constructs/ecs-agent-cluster';
4141
import { FanOutConsumer } from '../constructs/fanout-consumer';
4242
import { LinearIntegration } from '../constructs/linear-integration';
4343
import { RepoTable } from '../constructs/repo-table';
4444
import { SlackIntegration } from '../constructs/slack-integration';
4545
import { StrandedTaskReconciler } from '../constructs/stranded-task-reconciler';
46-
// import { EcsAgentCluster } from '../constructs/ecs-agent-cluster';
4746
import { TaskApi } from '../constructs/task-api';
4847
import { TaskApprovalsTable } from '../constructs/task-approvals-table';
4948
import { TaskDashboard } from '../constructs/task-dashboard';
@@ -519,26 +518,25 @@ export class AgentStack extends Stack {
519518
description: 'Name of the S3 bucket storing --trace trajectory artifacts (design §10.1)',
520519
});
521520

522-
// --- ECS Fargate compute backend (optional) ---
523-
// To enable ECS as an alternative compute backend, uncomment the block below
524-
// and the EcsAgentCluster import at the top of this file. Repos can then use
525-
// compute_type: 'ecs' in their blueprint config to route tasks to ECS Fargate.
526-
//
527-
// const agentImageAsset = new ecr_assets.DockerImageAsset(this, 'AgentImage', {
528-
// directory: repoRoot,
529-
// file: 'agent/Dockerfile',
530-
// platform: ecr_assets.Platform.LINUX_ARM64,
531-
// });
532-
//
533-
// const ecsCluster = new EcsAgentCluster(this, 'EcsAgentCluster', {
534-
// vpc: agentVpc.vpc,
535-
// agentImageAsset,
536-
// taskTable: taskTable.table,
537-
// taskEventsTable: taskEventsTable.table,
538-
// userConcurrencyTable: userConcurrencyTable.table,
539-
// githubTokenSecret,
540-
// memoryId: agentMemory.memory.memoryId,
541-
// });
521+
// --- ECS Fargate compute backend (enabled when compute_type=ecs) ---
522+
const computeType = this.node.tryGetContext('compute_type') ?? 'agentcore';
523+
if (computeType === 'ecs') {
524+
const agentImageAsset = new ecr_assets.DockerImageAsset(this, 'AgentImage', {
525+
directory: repoRoot,
526+
file: 'agent/Dockerfile',
527+
platform: ecr_assets.Platform.LINUX_ARM64,
528+
});
529+
530+
new EcsAgentCluster(this, 'EcsAgentCluster', {
531+
vpc: agentVpc.vpc,
532+
agentImageAsset,
533+
taskTable: taskTable.table,
534+
taskEventsTable: taskEventsTable.table,
535+
userConcurrencyTable: userConcurrencyTable.table,
536+
githubTokenSecret,
537+
memoryId: agentMemory.memory.memoryId,
538+
});
539+
}
542540

543541
// --- Task Orchestrator (durable Lambda function) ---
544542
const orchestrator = new TaskOrchestrator(this, 'TaskOrchestrator', {

0 commit comments

Comments
 (0)