Skip to content
2 changes: 1 addition & 1 deletion cdk/src/constructs/agent-memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class AgentMemory extends Construct {
super(scope, id);

this.memory = new agentcore.Memory(this, 'Memory', {
memoryName: props?.memoryName ?? 'bgagent_memory',
Comment thread
scottschreckengaust marked this conversation as resolved.
memoryName: props?.memoryName,
description: 'Cross-task interaction memory for background coding agents',
expirationDuration: props?.expirationDuration ?? Duration.days(365),
memoryStrategies: [
Expand Down
4 changes: 3 additions & 1 deletion cdk/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
19 changes: 6 additions & 13 deletions cdk/src/stacks/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
});
Expand Down Expand Up @@ -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: [
Expand Down
4 changes: 2 additions & 2 deletions cdk/test/constructs/agent-memory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_]*$'),
});
});

Expand Down
2 changes: 1 addition & 1 deletion cdk/test/stacks/agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
});
Expand Down
Loading