Skip to content

Commit eae7b28

Browse files
authored
Merge pull request #149 from aws-samples/bedrock_agent_update_jan2025
chore(bedrock_agent): update sample with latest version
2 parents a693f9e + 66a2da6 commit eae7b28

File tree

3 files changed

+89
-57
lines changed

3 files changed

+89
-57
lines changed

samples/bedrock-agent/lib/bedrock-agent-stack.ts

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ export class BedrockAgentStack extends cdk.Stack {
6565
});
6666

6767
const agent = new bedrock.Agent(this, 'Agent', {
68-
foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_INSTANT_V1_2,
68+
foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
6969
instruction: 'You are a helpful and friendly agent that answers questions about literature.',
7070
knowledgeBases: [kb],
71-
enableUserInput: true,
71+
userInputEnabled: true,
7272
shouldPrepareAgent:true
7373
});
7474

@@ -79,23 +79,35 @@ export class BedrockAgentStack extends cdk.Stack {
7979
timeout:cdk.Duration.minutes(2)
8080
});
8181

82-
const actionGroup = new AgentActionGroup(this,'MyActionGroup',{
83-
actionGroupName: 'query-library',
82+
const actionGroup = new AgentActionGroup({
83+
name: 'query-library',
8484
description: 'Use these functions to get information about the books in the library.',
85-
actionGroupExecutor: {
86-
lambda: actionGroupFunction
87-
},
88-
actionGroupState: "ENABLED",
89-
apiSchema: bedrock.ApiSchema.fromAsset(path.join(__dirname, 'action-group.yaml')),
85+
executor: bedrock.ActionGroupExecutor.fromlambdaFunction(actionGroupFunction),
86+
enabled: true,
87+
apiSchema: bedrock.ApiSchema.fromLocalAsset(path.join(__dirname, 'action-group.yaml')),
9088
});
9189

92-
agent.addActionGroups([actionGroup])
90+
agent.addActionGroup(actionGroup);
9391

94-
agent.addAlias({
92+
const agentAlias2 = new bedrock.AgentAlias(this, 'myalias2', {
9593
aliasName: 'my-agent-alias',
96-
description:'alias for my agent'
97-
98-
})
94+
agent: agent,
95+
description: 'alias for my agent'
96+
});
97+
98+
// Add NAG suppression for the Agent's role policy
99+
NagSuppressions.addResourceSuppressionsByPath(
100+
this,
101+
`/${this.node.path}/Agent/Role/DefaultPolicy/Resource`,
102+
[
103+
{
104+
id: 'AwsSolutions-IAM5',
105+
reason: 'The Agent requires permissions to invoke the action group Lambda function',
106+
appliesTo: ['Resource::<ActionGroupFunctionFE14D1CB.Arn>:*'],
107+
},
108+
],
109+
true
110+
);
99111

100112
new cdk.CfnOutput(this, 'AgentId', {value: agent.agentId});
101113
new cdk.CfnOutput(this, 'KnowledgeBaseId', {value: kb.knowledgeBaseId});
@@ -108,10 +120,29 @@ export class BedrockAgentStack extends cdk.Stack {
108120
{
109121
id: 'AwsSolutions-IAM4',
110122
reason: 'ActionGroup Lambda uses the AWSLambdaBasicExecutionRole AWS Managed Policy.',
123+
},
124+
{
125+
id: 'AwsSolutions-L1',
126+
reason: 'Using Python 3.12 as the latest runtime version for Lambda.',
111127
}
112128
],
113129
true,
114130
);
131+
NagSuppressions.addResourceSuppressionsByPath(
132+
this,
133+
`/${this.node.path}/Agent/Role/DefaultPolicy`,
134+
[
135+
{
136+
id: 'AwsSolutions-IAM5',
137+
reason: 'The Lambda function requires broad permissions for logging and invocation.',
138+
appliesTo: [
139+
'Action::lambda:InvokeFunction',
140+
'Action::logs:*'
141+
],
142+
},
143+
],
144+
true,
145+
);
115146
NagSuppressions.addResourceSuppressionsByPath(
116147
this,
117148
`/${this.node.path}/LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8a/ServiceRole`,

samples/bedrock-agent/package-lock.json

Lines changed: 40 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/bedrock-agent/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
"@types/jest": "^27.5.2",
1515
"@types/node": "10.17.27",
1616
"@types/prettier": "2.6.0",
17-
"aws-cdk": "2.162.1",
17+
"aws-cdk": "2.176.0",
1818
"jest": "^27.5.1",
1919
"ts-jest": "^27.1.4",
2020
"ts-node": "^10.9.1",
2121
"typescript": "~3.9.7"
2222
},
2323
"dependencies": {
24-
"@aws-cdk/aws-lambda-python-alpha": "^2.162.1-alpha.0",
25-
"@cdklabs/generative-ai-cdk-constructs": "^0.1.275",
26-
"aws-cdk-lib": "^2.162.1",
24+
"@aws-cdk/aws-lambda-python-alpha": "^2.176.0-alpha.0",
25+
"@cdklabs/generative-ai-cdk-constructs": "^0.1.290",
26+
"aws-cdk-lib": "^2.176.0",
2727
"cdk-nag": "^2.28.13",
2828
"constructs": "^10.0.0",
2929
"source-map-support": "^0.5.21"

0 commit comments

Comments
 (0)