TLDR: Amazon Web Services has released a new Terraform-based Infrastructure as Code (IaC) solution to streamline the deployment of Amazon Bedrock Knowledge Bases for Retrieval Augmented Generation (RAG) powered generative AI applications. This solution automates the setup of necessary AWS services like IAM roles, Amazon OpenSearch Serverless, and Amazon S3, enabling developers to quickly implement RAG workflows in production environments.
Amazon Web Services (AWS) has introduced a new Infrastructure as Code (IaC) solution utilizing Terraform to simplify and automate the deployment of Amazon Bedrock Knowledge Bases for Retrieval Augmented Generation (RAG) based generative AI applications. This initiative addresses the need for a robust, programmatic approach to managing AI infrastructure, moving beyond manual console configurations to production-ready deployments.
The Need for Automated Deployment
While Amazon Bedrock Knowledge Bases offer an intuitive console-based setup for initial development, migrating these configurations to a production environment requires a more structured and repeatable method. Many organizations prefer Terraform for its IaC capabilities, which allow for consistent and scalable infrastructure management. This new solution provides a Terraform template to bridge that gap, offering a streamlined path for deploying RAG workflows.
Solution Architecture and Components
The Terraform solution automates the creation and configuration of several critical AWS service components:
AWS Identity and Access Management (IAM) role: Establishes secure access and execution policies across integrated services.
Amazon OpenSearch Serverless: Configures an index collection for efficient management and querying of large datasets, serving as the vector store for the knowledge base.
Amazon Bedrock Knowledge Bases: Provides foundation models (FMs) and agents with contextual information from proprietary data sources, enabling more relevant, accurate, and customized responses.
The architecture incorporates specific IAM policies to govern permissions, including Amazon Bedrock invocation policies, Amazon S3 access policies for data storage, and OpenSearch data access policies. Additionally, OpenSearch collection access, data encryption, and network policies are defined to ensure secure and compliant data handling.
Prerequisites for Deployment
To successfully implement this solution, users must have an active AWS account with an IAM role possessing the necessary permissions for Amazon S3, Amazon OpenSearch Service, and Amazon Bedrock. Terraform must be installed locally, and the AWS Command Line Interface (AWS CLI) configured with appropriate credentials. Furthermore, an Amazon S3 bucket with documents in supported formats (TXT, MD, HTML, DOC, DOCX, CSL, XLS, XLSX, PDF) must be prepared as the data source.
Foundation Model Access
Crucially, access to a foundation model capable of generating embeddings, such as the default Titan Text Embeddings V2 model, must be enabled within the Amazon Bedrock console. The article provides a step-by-step guide for enabling this model access.
Project Setup and Deployment Workflow
The deployment process involves cloning the AWS Samples GitHub repository, navigating to the project directory, and updating the AWS Region and S3 bucket name in the main.tf file. Optional configurations for chunking strategies (DEFAULT, FIXED_SIZE, HIERARCHICAL, SEMANTIC) and OpenSearch vector dimensions can be adjusted in the variables.tf file. After configuration, terraform init initializes the working directory, terraform plan reviews proposed changes, and terraform apply deploys the infrastructure.
Advanced Customization
Developers can fine-tune the RAG application by customizing chunking parameters. For FIXED_SIZE chunking, fixed_size_max_tokens and fixed_size_overlap_percentage can be modified. HIERARCHICAL chunking allows adjustments to hierarchical_parent_max_tokens, hierarchical_child_max_tokens, and hierarchical_overlap_tokens. SEMANTIC chunking offers semantic_max_tokens, semantic_buffer_size, and semantic_breakpoint_percentile_threshold for granular control. The vector_dimension for the OpenSearch collection can also be adjusted to optimize retrieval precision or storage/query performance.
Testing and Cleanup
Post-deployment, the knowledge base can be tested directly within the Amazon Bedrock console by syncing data, selecting a foundation model, and submitting queries. For cleanup, terraform destroy removes all deployed resources, followed by manual deletion of S3 bucket contents and Terraform state files to avoid incurring unnecessary costs.
About the Authors
Also Read:
- Elysia: A New Open-Source Python Framework Revolutionizes Agentic RAG with Decision Trees and Advanced Data Handling
- Amazon Unveils Alexa+ with Advanced Generative AI for Seamless Conversations and Enhanced Shopping
The solution was developed by Andrew Ang, a Senior ML Engineer, and Akhil Nooney, a Deep Learning Architect, both from the AWS Generative AI Innovation Center. They specialize in helping customers implement generative AI proof-of-concept projects and design scalable, production-ready solutions.


