To deploy AWS Bedrock using Terraform beyond basic resource documentation, consider the following structured approach that integrates best practices, modular design, and service integrations:
Key Components to Automate
-
IAM Roles & Policies
-
S3 Bucket for Data
-
Model Deployment
- Use
aws_bedrock_provisioned_model_throughput (if supported) to deploy models:
resource "aws_bedrock_provisioned_model_throughput" "claude" {
model_name = "anthropic.claude-v2"
name = "claude-throughput"
preflight_optimization = true
provisioned_model_name = "claude-provisioned"
throughput_id = "my-throughput-id"
}
- If unsupported: Use a
null_resource with local-exec to invoke AWS CLI:
resource "null_resource" "deploy_model" {
provisioner "local-exec" {
command = "aws bedrock create-provisioned-model-throughput --model-name anthropic.claude-v2 ..."
}
}
-
VPC Configuration (Optional)
-
Lambda Function for API Integration
-
API Gateway
-
Monitoring & Security
Modular Structure Example
Organize code into modules for scalability:
modules/
├── bedrock/
│ ├── main.tf
│ ├── iam.tf
│ └── outputs.tf
├── lambda/
│ ├── main.tf
│ └── api-gateway.tf
└── vpc/
├── endpoints.tf
└── sg.tf
CI/CD & State Management
Testing & Validation
Add a null_resource to validate deployment:
resource "null_resource" "test_inference" {
provisioner "local-exec" {
command = "curl -X POST https://${aws_apigatewayv2_api.bedrock_api.api_id}.execute-api.${var.region}.amazonaws.com/prod/invoke -d '{\"prompt\": \"Hello\"}'"
}
}
Important Notes
- Model Availability: Ensure your AWS account has access to required models (some require manual acceptance in the console).
- Provider Version: Use the latest AWS provider (
~> 5.x) for Bedrock support.
- Cost Management: Monitor provisioned throughput costs (models like Claude or Llama incur hourly charges).
This approach balances automation with practical workarounds for Terraform's current Bedrock limitations. Adjust based on your use case (e.g., replace Lambda with SageMaker for custom models).