Skip to content

Commit 759a8cd

Browse files
authored
Merge branch 'main' into bedrock-guardrails-l2
2 parents 2739eb7 + 87770ef commit 759a8cd

File tree

70 files changed

+4372
-488
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+4372
-488
lines changed

.github/workflows/pr-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ concurrency:
1919
cancel-in-progress: true
2020

2121
jobs:
22-
build:
22+
pr-build:
2323
if: github.repository != 'aws/aws-cdk'
2424
runs-on: aws-cdk_ubuntu-latest_32-core
2525

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
"fs-extra": "^9.1.0",
2626
"graceful-fs": "^4.2.11",
2727
"jest-junit": "^13.2.0",
28-
"jsii-diff": "1.112.0",
29-
"jsii-pacmak": "1.112.0",
30-
"jsii-reflect": "1.112.0",
31-
"lerna": "^8.2.3",
28+
"jsii-diff": "1.113.0",
29+
"jsii-pacmak": "1.113.0",
30+
"jsii-reflect": "1.113.0",
31+
"lerna": "^8.2.4",
3232
"nx": "^20",
3333
"semver": "^7.7.2",
3434
"standard-version": "^9.5.0",

packages/@aws-cdk-testing/framework-integ/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"license": "Apache-2.0",
3131
"devDependencies": {
3232
"@aws-cdk/cdk-build-tools": "0.0.0",
33-
"@aws-cdk/integ-runner": "^2.188.3",
33+
"@aws-cdk/integ-runner": "^2.189.2",
3434
"@aws-cdk/pkglint": "0.0.0",
3535
"@aws-sdk/client-acm": "3.632.0",
3636
"@aws-sdk/client-rds": "3.632.0",
@@ -49,7 +49,7 @@
4949
"@aws-cdk/lambda-layer-kubectl-v33": "^2.0.0",
5050
"@aws-cdk/region-info": "0.0.0",
5151
"aws-cdk-lib": "0.0.0",
52-
"cdk8s": "2.69.76",
52+
"cdk8s": "2.70.3",
5353
"cdk8s-plus-27": "2.9.5",
5454
"constructs": "^10.0.0"
5555
},

packages/@aws-cdk/app-staging-synthesizer-alpha/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
},
9090
"devDependencies": {
9191
"aws-cdk-lib": "0.0.0",
92-
"@aws-cdk/integ-runner": "^2.188.3",
92+
"@aws-cdk/integ-runner": "^2.189.2",
9393
"@aws-cdk/integ-tests-alpha": "0.0.0",
9494
"constructs": "^10.0.0",
9595
"@aws-cdk/cdk-build-tools": "0.0.0",

packages/@aws-cdk/aws-amplify-alpha/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"license": "Apache-2.0",
8888
"devDependencies": {
8989
"@aws-cdk/cdk-build-tools": "0.0.0",
90-
"@aws-cdk/integ-runner": "^2.188.3",
90+
"@aws-cdk/integ-runner": "^2.189.2",
9191
"@aws-cdk/pkglint": "0.0.0",
9292
"@aws-cdk/custom-resource-handlers": "0.0.0",
9393
"@aws-sdk/client-amplify": "3.632.0",

packages/@aws-cdk/aws-applicationsignals-alpha/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"license": "Apache-2.0",
8585
"devDependencies": {
8686
"@aws-cdk/cdk-build-tools": "0.0.0",
87-
"@aws-cdk/integ-runner": "^2.188.3",
87+
"@aws-cdk/integ-runner": "^2.189.2",
8888
"@aws-cdk/integ-tests-alpha": "0.0.0",
8989
"@aws-cdk/pkglint": "0.0.0",
9090
"@types/jest": "^29.5.14",

packages/@aws-cdk/aws-apprunner-alpha/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
"devDependencies": {
8787
"@aws-cdk/cdk-build-tools": "0.0.0",
8888
"aws-cdk-lib": "0.0.0",
89-
"@aws-cdk/integ-runner": "^2.188.3",
89+
"@aws-cdk/integ-runner": "^2.189.2",
9090
"@aws-cdk/pkglint": "0.0.0",
9191
"@types/jest": "^29.5.14",
9292
"constructs": "^10.0.0",

packages/@aws-cdk/aws-bedrock-alpha/README.md

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ This construct library facilitates the deployment of Bedrock Agents, enabling yo
5757
- [Prompt Properties](#prompt-properties)
5858
- [Prompt Version](#prompt-version)
5959
- [Import Methods](#import-methods)
60+
- [Inference Profiles](#inference-profiles)
61+
- [Using Inference Profiles](#using-inference-profiles)
62+
- [Types of Inference Profiles](#types-of-inference-profiles)
63+
- [Prompt Routers](#prompt-routers)
64+
- [Inference Profile Permissions](#inference-profile-permissions)
65+
- [Inference Profiles Import Methods](#inference-profiles-import-methods)
6066

6167
## Agents
6268

@@ -1343,3 +1349,202 @@ const importedPrompt = bedrock.Prompt.fromPromptAttributes(this, 'ImportedPrompt
13431349
promptVersion: '1', // optional, defaults to 'DRAFT'
13441350
});
13451351
```
1352+
1353+
## Inference Profiles
1354+
1355+
Amazon Bedrock Inference Profiles provide a way to manage and optimize inference configurations for your foundation models. They allow you to define reusable configurations that can be applied across different prompts and agents.
1356+
1357+
### Using Inference Profiles
1358+
1359+
Inference profiles can be used with prompts and agents to maintain consistent inference configurations across your application.
1360+
1361+
#### With Agents
1362+
1363+
```ts fixture=default
1364+
// Create a cross-region inference profile
1365+
const crossRegionProfile = bedrock.CrossRegionInferenceProfile.fromConfig({
1366+
geoRegion: bedrock.CrossRegionInferenceProfileRegion.US,
1367+
model: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
1368+
});
1369+
1370+
// Use the cross-region profile with an agent
1371+
const agent = new bedrock.Agent(this, 'Agent', {
1372+
foundationModel: crossRegionProfile,
1373+
instruction: 'You are a helpful and friendly agent that answers questions about agriculture.',
1374+
});
1375+
```
1376+
1377+
#### With Prompts
1378+
1379+
```ts fixture=default
1380+
// Create a prompt router for intelligent model selection
1381+
const promptRouter = bedrock.PromptRouter.fromDefaultId(
1382+
bedrock.DefaultPromptRouterIdentifier.ANTHROPIC_CLAUDE_V1,
1383+
'us-east-1'
1384+
);
1385+
1386+
// Use the prompt router with a prompt variant
1387+
const variant = bedrock.PromptVariant.text({
1388+
variantName: 'variant1',
1389+
promptText: 'What is the capital of France?',
1390+
model: promptRouter,
1391+
});
1392+
1393+
new bedrock.Prompt(this, 'Prompt', {
1394+
promptName: 'prompt-router-test',
1395+
variants: [variant],
1396+
});
1397+
```
1398+
1399+
### Types of Inference Profiles
1400+
1401+
Amazon Bedrock offers two types of inference profiles:
1402+
1403+
#### Application Inference Profiles
1404+
1405+
Application inference profiles are user-defined profiles that help you track costs and model usage. They can be created for a single region or for multiple regions using a cross-region inference profile.
1406+
1407+
##### Single Region Application Profile
1408+
1409+
```ts fixture=default
1410+
// Create an application inference profile for one Region
1411+
const appProfile = new bedrock.ApplicationInferenceProfile(this, 'MyApplicationProfile', {
1412+
applicationInferenceProfileName: 'claude-3-sonnet-v1',
1413+
modelSource: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_V1_0,
1414+
description: 'Application profile for cost tracking',
1415+
tags: {
1416+
Environment: 'Production',
1417+
},
1418+
});
1419+
```
1420+
1421+
##### Multi-Region Application Profile
1422+
1423+
```ts fixture=default
1424+
// Create a cross-region inference profile
1425+
const crossRegionProfile = bedrock.CrossRegionInferenceProfile.fromConfig({
1426+
geoRegion: bedrock.CrossRegionInferenceProfileRegion.US,
1427+
model: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V2_0,
1428+
});
1429+
1430+
// Create an application inference profile across regions
1431+
const appProfile = new bedrock.ApplicationInferenceProfile(this, 'MyMultiRegionProfile', {
1432+
applicationInferenceProfileName: 'claude-35-sonnet-v2-multi-region',
1433+
modelSource: crossRegionProfile,
1434+
description: 'Multi-region application profile for cost tracking',
1435+
});
1436+
```
1437+
1438+
#### System Defined Inference Profiles
1439+
1440+
Cross-region inference enables you to seamlessly manage unplanned traffic bursts by utilizing compute across different AWS Regions. With cross-region inference, you can distribute traffic across multiple AWS Regions, enabling higher throughput and enhanced resilience during periods of peak demands.
1441+
1442+
Before using a CrossRegionInferenceProfile, ensure that you have access to the models and regions defined in the inference profiles. For instance, if you use the system defined inference profile "us.anthropic.claude-3-5-sonnet-20241022-v2:0", inference requests will be routed to US East (Virginia) us-east-1, US East (Ohio) us-east-2 and US West (Oregon) us-west-2. Thus, you need to have model access enabled in those regions for the model anthropic.claude-3-5-sonnet-20241022-v2:0.
1443+
1444+
##### System Defined Profile Configuration
1445+
1446+
```ts fixture=default
1447+
const crossRegionProfile = bedrock.CrossRegionInferenceProfile.fromConfig({
1448+
geoRegion: bedrock.CrossRegionInferenceProfileRegion.US,
1449+
model: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V2_0,
1450+
});
1451+
```
1452+
1453+
### Prompt Routers
1454+
1455+
Amazon Bedrock intelligent prompt routing provides a single serverless endpoint for efficiently routing requests between different foundational models within the same model family. It can help you optimize for response quality and cost. They offer a comprehensive solution for managing multiple AI models through a single serverless endpoint, simplifying the process for you. Intelligent prompt routing predicts the performance of each model for each request, and dynamically routes each request to the model that it predicts is most likely to give the desired response at the lowest cost.
1456+
1457+
#### Default and Custom Prompt Routers
1458+
1459+
```ts fixture=default
1460+
// Use a default prompt router
1461+
const variant = bedrock.PromptVariant.text({
1462+
variantName: 'variant1',
1463+
promptText: 'What is the capital of France?',
1464+
model: bedrock.PromptRouter.fromDefaultId(
1465+
bedrock.DefaultPromptRouterIdentifier.ANTHROPIC_CLAUDE_V1,
1466+
'us-east-1'
1467+
),
1468+
});
1469+
1470+
new bedrock.Prompt(this, 'Prompt', {
1471+
promptName: 'prompt-router-test',
1472+
variants: [variant],
1473+
});
1474+
```
1475+
1476+
### Inference Profile Permissions
1477+
1478+
Use the `grantProfileUsage` method to grant appropriate permissions to resources that need to use the inference profile.
1479+
1480+
#### Granting Profile Usage Permissions
1481+
1482+
```ts fixture=default
1483+
// Create an application inference profile
1484+
const profile = new bedrock.ApplicationInferenceProfile(this, 'MyProfile', {
1485+
applicationInferenceProfileName: 'my-profile',
1486+
modelSource: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
1487+
});
1488+
1489+
// Create a Lambda function
1490+
const lambdaFunction = new lambda.Function(this, 'MyFunction', {
1491+
runtime: lambda.Runtime.PYTHON_3_11,
1492+
handler: 'index.handler',
1493+
code: lambda.Code.fromInline('def handler(event, context): return "Hello"'),
1494+
});
1495+
1496+
// Grant the Lambda function permission to use the inference profile
1497+
profile.grantProfileUsage(lambdaFunction);
1498+
1499+
// Use a system defined inference profile
1500+
const crossRegionProfile = bedrock.CrossRegionInferenceProfile.fromConfig({
1501+
geoRegion: bedrock.CrossRegionInferenceProfileRegion.US,
1502+
model: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
1503+
});
1504+
1505+
// Grant permissions to use the cross-region inference profile
1506+
crossRegionProfile.grantProfileUsage(lambdaFunction);
1507+
```
1508+
1509+
The `grantProfileUsage` method adds the necessary IAM permissions to the resource, allowing it to use the inference profile. This includes permissions to call `bedrock:GetInferenceProfile` and `bedrock:ListInferenceProfiles` actions on the inference profile resource.
1510+
1511+
### Inference Profiles Import Methods
1512+
1513+
You can import existing application inference profiles using the following methods:
1514+
1515+
```ts fixture=default
1516+
// Import an inference profile through attributes
1517+
const importedProfile = bedrock.ApplicationInferenceProfile.fromApplicationInferenceProfileAttributes(
1518+
this,
1519+
'ImportedProfile',
1520+
{
1521+
inferenceProfileArn: 'arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/my-profile-id',
1522+
inferenceProfileIdentifier: 'my-profile-id',
1523+
}
1524+
);
1525+
```
1526+
1527+
You can also import an application inference profile from an existing L1 CloudFormation construct:
1528+
1529+
```ts fixture=default
1530+
// Create or reference an existing L1 CfnApplicationInferenceProfile
1531+
const cfnProfile = new aws_bedrock_cfn.CfnApplicationInferenceProfile(this, 'CfnProfile', {
1532+
inferenceProfileName: 'my-cfn-profile',
1533+
modelSource: {
1534+
copyFrom: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0.invokableArn,
1535+
},
1536+
description: 'Profile created via L1 construct',
1537+
});
1538+
1539+
// Import the L1 construct as an L2 ApplicationInferenceProfile
1540+
const importedFromCfn = bedrock.ApplicationInferenceProfile.fromCfnApplicationInferenceProfile(cfnProfile);
1541+
1542+
// Grant permissions to use the imported profile
1543+
const lambdaFunction = new lambda.Function(this, 'MyFunction', {
1544+
runtime: lambda.Runtime.PYTHON_3_11,
1545+
handler: 'index.handler',
1546+
code: lambda.Code.fromInline('def handler(event, context): return "Hello"'),
1547+
});
1548+
1549+
importedFromCfn.grantProfileUsage(lambdaFunction);
1550+
```

packages/@aws-cdk/aws-bedrock-alpha/bedrock/agents/agent.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ export class Agent extends AgentBase implements IAgent {
522522
this.agentCollaboration = props.agentCollaboration;
523523
if (props.agentCollaboration) {
524524
props.agentCollaboration.collaborators.forEach(ac => {
525-
this.addAgentCollaborator(ac);
525+
this.grantPermissionToAgent(ac);
526526
});
527527
}
528528

@@ -662,11 +662,14 @@ export class Agent extends AgentBase implements IAgent {
662662
}
663663

664664
/**
665-
* Adds a collaborator to the agent and grants necessary permissions.
666-
* @param agentCollaborator - The collaborator to add
667-
* @internal This method is used internally by the constructor and should not be called directly.
665+
* Grants permissions for an agent collaborator to this agent's role.
666+
* This method only grants IAM permissions and does not add the collaborator
667+
* to the agent's collaboration configuration. To add collaborators to the
668+
* agent configuration, include them in the AgentCollaboration when creating the agent.
669+
*
670+
* @param agentCollaborator - The collaborator to grant permissions for
668671
*/
669-
private addAgentCollaborator(agentCollaborator: AgentCollaborator) {
672+
private grantPermissionToAgent(agentCollaborator: AgentCollaborator) {
670673
agentCollaborator.grant(this.role);
671674
}
672675

@@ -722,7 +725,7 @@ export class Agent extends AgentBase implements IAgent {
722725
* @internal This is an internal core function and should not be called directly.
723726
*/
724727
private renderAgentCollaborators(): bedrock.CfnAgent.AgentCollaboratorProperty[] | undefined {
725-
if (!this.agentCollaboration) {
728+
if (!this.agentCollaboration || !this.agentCollaboration.collaborators || this.agentCollaboration.collaborators.length === 0) {
726729
return undefined;
727730
}
728731

packages/@aws-cdk/aws-bedrock-alpha/bedrock/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ export * from './prompts/prompt-inference-configuration';
3333
export * from './prompts/prompt-template-configuration';
3434
export * from './prompts/prompt-genai-resource';
3535

36+
// ===================================
37+
// Inference Profiles
38+
// ===================================
39+
export * from './inference-profiles/inference-profile';
40+
export * from './inference-profiles/application-inference-profile';
41+
export * from './inference-profiles/cross-region-inference-profile';
42+
export * from './inference-profiles/prompt-router';
43+
3644
// ===================================
3745
// Models
3846
// ===================================

0 commit comments

Comments
 (0)