diff --git a/cdk/src/constructs/agent-memory.ts b/cdk/src/constructs/agent-memory.ts index 9af312bd..7ba4de66 100644 --- a/cdk/src/constructs/agent-memory.ts +++ b/cdk/src/constructs/agent-memory.ts @@ -70,7 +70,7 @@ export class AgentMemory extends Construct { super(scope, id); this.memory = new agentcore.Memory(this, 'Memory', { - memoryName: props?.memoryName ?? 'bgagent_memory', + memoryName: props?.memoryName, description: 'Cross-task interaction memory for background coding agents', expirationDuration: props?.expirationDuration ?? Duration.days(365), memoryStrategies: [ diff --git a/cdk/src/main.ts b/cdk/src/main.ts index b64838e4..880dd005 100644 --- a/cdk/src/main.ts +++ b/cdk/src/main.ts @@ -31,9 +31,11 @@ const app = new App(); Aspects.of(app).add(new AwsSolutionsChecks()); +const stackName = app.node.tryGetContext('stackName') ?? 'backgroundagent-dev'; + new AgentStack( app, - 'backgroundagent-dev', + stackName, { env: devEnv, description: 'ABCA Development Stack', diff --git a/cdk/src/stacks/agent.ts b/cdk/src/stacks/agent.ts index 74443e58..7d5c3d08 100644 --- a/cdk/src/stacks/agent.ts +++ b/cdk/src/stacks/agent.ts @@ -119,17 +119,15 @@ export class AgentStack extends Stack { }, ]); - const runtimeName = 'jean_cloude'; - // Log groups (created before runtime so we can reference the name in env vars) const applicationLogGroup = new logs.LogGroup(this, 'RuntimeApplicationLogGroup', { - logGroupName: `/aws/vendedlogs/bedrock-agentcore/runtime/APPLICATION_LOGS/${runtimeName}`, + logGroupName: `/aws/vendedlogs/bedrock-agentcore/runtime/APPLICATION_LOGS/${this.stackName}`, retention: logs.RetentionDays.THREE_MONTHS, removalPolicy: RemovalPolicy.DESTROY, }); const usageLogGroup = new logs.LogGroup(this, 'RuntimeUsageLogGroup', { - logGroupName: `/aws/vendedlogs/bedrock-agentcore/runtime/USAGE_LOGS/${runtimeName}`, + logGroupName: `/aws/vendedlogs/bedrock-agentcore/runtime/USAGE_LOGS/${this.stackName}`, retention: logs.RetentionDays.THREE_MONTHS, removalPolicy: RemovalPolicy.DESTROY, }); @@ -164,7 +162,7 @@ export class AgentStack extends Stack { // --- Bedrock Guardrail for prompt injection detection --- // (Declared early so TaskApi — constructed before the runtimes — can reference it.) const inputGuardrail = new bedrock.Guardrail(this, 'InputGuardrail', { - guardrailName: 'task-input-guardrail', + guardrailName: `task-input-guardrail-${this.stackName}`.slice(0, 50), description: 'Screens task submissions for prompt injection attacks', contentFilters: [ { @@ -284,7 +282,6 @@ export class AgentStack extends Stack { // AgentCore's account-level runtimeName uniqueness and triggering an // UPDATE_ROLLBACK. const runtime = new agentcore.Runtime(this, 'Runtime', { - runtimeName, agentRuntimeArtifact: artifact, networkConfiguration: runtimeNetworkConfig, environmentVariables: runtimeEnvironmentVariables, @@ -618,7 +615,7 @@ export class AgentStack extends Stack { // --- Bedrock model invocation logging (account-level) --- const invocationLogGroup = new logs.LogGroup(this, 'ModelInvocationLogGroup', { - logGroupName: '/aws/bedrock/model-invocation-logs', + logGroupName: `/aws/bedrock/model-invocation-logs/${this.stackName}`, retention: logs.RetentionDays.THREE_MONTHS, removalPolicy: RemovalPolicy.DESTROY, }); @@ -671,12 +668,8 @@ export class AgentStack extends Stack { physicalResourceId: cr.PhysicalResourceId.of('bedrock-invocation-logging'), ignoreErrorCodesMatching: '.*', }, - onDelete: { - service: 'Bedrock', - action: 'deleteModelInvocationLoggingConfiguration', - parameters: {}, - ignoreErrorCodesMatching: '.*', - }, + // onDelete intentionally omitted — model invocation logging is account-level; + // deleting one stack should not disable logging that another stack relies on. policy: cr.AwsCustomResourcePolicy.fromStatements([ new iam.PolicyStatement({ actions: [ diff --git a/cdk/test/constructs/agent-memory.test.ts b/cdk/test/constructs/agent-memory.test.ts index 09407fae..9512e129 100644 --- a/cdk/test/constructs/agent-memory.test.ts +++ b/cdk/test/constructs/agent-memory.test.ts @@ -42,10 +42,10 @@ describe('AgentMemory construct', () => { template.resourceCountIs('AWS::BedrockAgentCore::Memory', 1); }); - test('uses default memory name', () => { + test('auto-generates memory name when not provided', () => { const { template } = createStack(); template.hasResourceProperties('AWS::BedrockAgentCore::Memory', { - Name: 'bgagent_memory', + Name: Match.stringLikeRegexp('^[a-zA-Z][a-zA-Z0-9_]*$'), }); }); diff --git a/cdk/test/stacks/agent.test.ts b/cdk/test/stacks/agent.test.ts index 8bb86218..f62d291f 100644 --- a/cdk/test/stacks/agent.test.ts +++ b/cdk/test/stacks/agent.test.ts @@ -296,7 +296,7 @@ describe('AgentStack', () => { test('creates a log group for model invocation logs', () => { template.hasResourceProperties('AWS::Logs::LogGroup', { - LogGroupName: '/aws/bedrock/model-invocation-logs', + LogGroupName: '/aws/bedrock/model-invocation-logs/TestAgentStack', RetentionInDays: 90, }); });