Skip to content

Commit f32b386

Browse files
authored
chore(deps): add dependency to resource for CRIS (#909)
* chore(deps): add dependency to resource for CRIS
1 parent 168c0d9 commit f32b386

File tree

5 files changed

+33
-11
lines changed

5 files changed

+33
-11
lines changed

src/cdk-lib/bedrock/agents/agent.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,6 @@ export class Agent extends AgentBase {
378378
},
379379
}),
380380
});
381-
// add the appropriate permissions to use the FM
382-
this.foundationModel.grantInvoke(this.role);
383381
}
384382
// ------------------------------------------------------
385383
// Set Lazy Props initial values
@@ -437,6 +435,15 @@ export class Agent extends AgentBase {
437435
this.agentArn = this.__resource.attrAgentArn;
438436
this.agentVersion = this.__resource.attrAgentVersion;
439437
this.lastUpdated = this.__resource.attrUpdatedAt;
438+
439+
// Add explicit dependency between the agent resource and the agent's role default policy
440+
// See https://github.com/awslabs/generative-ai-cdk-constructs/issues/899
441+
if (!props.existingRole) {
442+
// add the appropriate permissions to use the FM
443+
const grant = this.foundationModel.grantInvoke(this.role);
444+
grant.applyBefore(this.__resource);
445+
}
446+
440447
this.testAlias = AgentAlias.fromAttributes(this, 'DefaultAlias', {
441448
aliasId: 'TSTALIASID',
442449
aliasName: 'AgentTestAlias',

test/integ/inference-profiles.integ.snapshot/aws-cdk-bedrock-guardrails-integ-test.assets.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"version": "39.0.0",
33
"files": {
4-
"8371c500cdb7d7db47b783ce965da719cc175fa62f9299c41a60f868691dbe0a": {
4+
"fc1142f404eb5443446b22592dc6d75ae8c80055bfb9474da78f4254ae394a4f": {
55
"source": {
66
"path": "aws-cdk-bedrock-guardrails-integ-test.template.json",
77
"packaging": "file"
88
},
99
"destinations": {
1010
"current_account-eu-central-1": {
1111
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-eu-central-1",
12-
"objectKey": "8371c500cdb7d7db47b783ce965da719cc175fa62f9299c41a60f868691dbe0a.json",
12+
"objectKey": "fc1142f404eb5443446b22592dc6d75ae8c80055bfb9474da78f4254ae394a4f.json",
1313
"region": "eu-central-1",
1414
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-eu-central-1"
1515
}

test/integ/inference-profiles.integ.snapshot/aws-cdk-bedrock-guardrails-integ-test.template.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@
124124
"IdleSessionTTLInSeconds": 3600,
125125
"Instruction": "You are a test bot that needs to be very gentle and useful to the user",
126126
"SkipResourceInUseCheckOnDelete": false
127-
}
127+
},
128+
"DependsOn": [
129+
"TestAgentsimpleRoleDefaultPolicy585202B2"
130+
]
128131
},
129132
"TestAgentcrisRole15797E3B": {
130133
"Type": "AWS::IAM::Role",
@@ -277,7 +280,10 @@
277280
"IdleSessionTTLInSeconds": 3600,
278281
"Instruction": "You are a test bot that needs to be very gentle and useful to the user",
279282
"SkipResourceInUseCheckOnDelete": false
280-
}
283+
},
284+
"DependsOn": [
285+
"TestAgentcrisRoleDefaultPolicy6C083E13"
286+
]
281287
},
282288
"TestAppProfile97C615D8": {
283289
"Type": "AWS::Bedrock::ApplicationInferenceProfile",
@@ -463,7 +469,10 @@
463469
"IdleSessionTTLInSeconds": 3600,
464470
"Instruction": "You are a test bot that needs to be very gentle and useful to the user",
465471
"SkipResourceInUseCheckOnDelete": false
466-
}
472+
},
473+
"DependsOn": [
474+
"TestAgentaipRoleDefaultPolicyD4F0F0D5"
475+
]
467476
}
468477
},
469478
"Parameters": {

test/integ/issue747.integ.snapshot/aws-cdk-bedrock-agents-integ-test.assets.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"version": "39.0.0",
33
"files": {
4-
"af068d207758560bdaa77dd8cf7bc3626034f1d007a7d014cb51363863752caa": {
4+
"edce2cdca448655b4baa3a3f25397547640d54472ced24d6b7c09954e1b4a72c": {
55
"source": {
66
"path": "aws-cdk-bedrock-agents-integ-test.template.json",
77
"packaging": "file"
88
},
99
"destinations": {
1010
"current_account-eu-central-1": {
1111
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-eu-central-1",
12-
"objectKey": "af068d207758560bdaa77dd8cf7bc3626034f1d007a7d014cb51363863752caa.json",
12+
"objectKey": "edce2cdca448655b4baa3a3f25397547640d54472ced24d6b7c09954e1b4a72c.json",
1313
"region": "eu-central-1",
1414
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-eu-central-1"
1515
}

test/integ/issue747.integ.snapshot/aws-cdk-bedrock-agents-integ-test.template.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,10 @@
166166
"IdleSessionTTLInSeconds": 3600,
167167
"Instruction": "You are a helpful and friendly agent that answers questions about literature.",
168168
"SkipResourceInUseCheckOnDelete": false
169-
}
169+
},
170+
"DependsOn": [
171+
"AgentRoleDefaultPolicyA34CCA36"
172+
]
170173
},
171174
"Agent2Role38FC3F9C": {
172175
"Type": "AWS::IAM::Role",
@@ -334,7 +337,10 @@
334337
"IdleSessionTTLInSeconds": 3600,
335338
"Instruction": "You are a helpful and friendly agent that answers questions about unicorns.",
336339
"SkipResourceInUseCheckOnDelete": false
337-
}
340+
},
341+
"DependsOn": [
342+
"Agent2RoleDefaultPolicy55328F4A"
343+
]
338344
},
339345
"ActionGroupFunctionServiceRole77660D62": {
340346
"Type": "AWS::IAM::Role",

0 commit comments

Comments
 (0)