This CDK application deploys OpenSearch Serverless collection for vector storage, configures necessary security policies, and integrates with Amazon Bedrock and Bedrock Agent. This shows how to automate the setup of Amazon Bedrock with agents and knowledge base using CDK
This solution sets up a vector index optimized for embedding storage, an S3 bucket for document management, and a Bedrock agent that can interact with the knowledge base through natural language.
This project deploys an AWS CDK application consisting of two stacks: OpenSearch Serverless and Amazon Bedrock integration.
Creates an OpenSearch Serverless collection
Sets up encryption, network, and data access policies
Creates an S3 bucket for document storage
Creates IAM roles for Bedrock integration
Creates a Knowledge Base using the OpenSearch collection
Sets up a data source connected to the S3 bucket
Creates a Bedrock agent with the Knowledge Base integration
The OpenSearch collection can take several minutes to become active
The vector index must be created after the collection is active and before deploying the Bedrock stack
The default vector dimension (1536) is set for Titan Embedding Model
Make sure to update the CONFIG values according to your requirements
The network policy allows public access - modify according to your security requirements
-
Clone the repository
-
Update
config.ts
in lib folder with required collection name, and iamUserArn with you IAM role/user ARN that has access to OpenSearch and Bedrock
export const CONFIG = {
collectionName: 'your-collection-name',
indexName: 'your-index-name',
iamUserArn: 'arn:aws:iam::YOUR_ACCOUNT_ID:user/YOUR_USER_NAME'
};
- Install dependencies:
npm install
- Deploy the OpenSearch stack:
cdk deploy opensearch-stack
- After the OpenSearch stack is deployed, create the vector index.
- Goto OpenSearch Serverless Dashboard
- Select the collection
- Select Create Vector Index
- Enter Indexname as mentioned in
config.ts
. cdk-index in this case. - Click on Add Vector Field, add name vector and dimension as 1536 (as we are using Amazon Titan Text Embedding v1)
- Screenshots of above steps are below
- Deploy the Bedrock stack:
cdk deploy bedrock-stack
-
Run below commands
cdk destroy bedrock-stack
cdk destroy opensearch-stack
OR
cdk destroy --all
See CONTRIBUTING for more information.
This library is licensed under the MIT-0 License. See the LICENSE file.