Skip to content

Commit e19f4c5

Browse files
feat: release bedrock agents sample (#23)
* feat: release bedrock agents sample --------- Signed-off-by: Scott Schreckengaust <[email protected]>
1 parent 43f31dc commit e19f4c5

File tree

6 files changed

+48
-25
lines changed

6 files changed

+48
-25
lines changed

samples/bedrock-agent/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ This project is built using [Terraform](https://www.terraform.io/). See [Getting
9696
5. Enable Access to Amazon Bedrock Models
9797
> You must explicitly enable access to models before they can be used with the Amazon Bedrock service. Please follow these steps in the [Amazon Bedrock User Guide](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html) to enable access to the models (```Anthropic::Claude```):.
9898

99+
_NOTE: The default architecture is `x86_64`, feel free to add `-var="architecture=$(python -c "import platform;print('x86_64' if platform.machine().upper() in ['X86', 'AMD64'] else 'arm64')")"` to inspect and use your platform's architecture or set it directly with the `arm64.tfvars`_
100+
99101
6. Check the plan.
100102
101103
```shell

samples/bedrock-agent/arm64.tfvars

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
architecture = "arm64"

samples/bedrock-agent/data.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# data "aws_bedrock_foundation_models" "test" {}
1+
data "aws_bedrock_foundation_models" "test" {}

samples/bedrock-agent/main.tf

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
variable "region" {
2-
type = string
3-
description = "AWS region to deploy the resources"
4-
default = "us-east-1"
5-
}
6-
71
provider "aws" {
82
region = var.region
93
}
@@ -19,13 +13,12 @@ provider "opensearch" {
1913

2014
module "bedrock" {
2115
#checkov:skip=CKV_TF_1:Terraform registry has no ability to use a commit hash
22-
# source = "aws-ia/bedrock/aws"
23-
# version = "0.0.3"
24-
source = "github.com/aws-ia/terraform-aws-bedrock//?ref=58798f1fcf95db48ce3f336c7e93d50c83e27ce8"
16+
source = "aws-ia/bedrock/aws"
17+
version = "0.0.3"
2518
create_kb = true
2619
create_default_kb = true
2720
create_agent = true
28-
foundation_model = "anthropic.claude-3-5-haiku-20241022-v1:0" # "anthropic.claude-v2"
21+
foundation_model = var.foundation_model
2922
instruction = "You are a helpful and friendly agent that answers questions about literature."
3023
create_ag = true
3124
action_group_name = "bedrock-agent-action-group"
@@ -36,25 +29,20 @@ module "bedrock" {
3629
}
3730

3831
module "lambda" {
32+
#checkov:skip=CKV_TF_1:Terraform registry has no ability to use a commit hash
3933
source = "terraform-aws-modules/lambda/aws"
4034
version = "7.15.0"
4135
function_name = "bedrock-agent-action"
4236
handler = "index.handler"
4337
runtime = "python3.12"
4438
publish = true
4539
timeout = 15
40+
architectures = ["${var.architecture}", ]
41+
layers = ["arn:aws:lambda:${var.region}:017000801446:layer:AWSLambdaPowertoolsPythonV3-python312-${var.architecture}:4", ]
4642
source_path = [
4743
{
4844
path = "${path.module}/lambda/action-group"
4945
poetry_install = true
5046
}
5147
]
52-
architectures = [
53-
"arm64",
54-
# "x86_64",
55-
]
56-
layers = [
57-
"arn:aws:lambda:${var.region}:017000801446:layer:AWSLambdaPowertoolsPythonV3-python312-arm64:4",
58-
# "arn:aws:lambda:${var.region}:017000801446:layer:AWSLambdaPowertoolsPythonV3-python312-x86_64:4",
59-
]
6048
}

samples/bedrock-agent/outputs.tf

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,4 @@ output "knowledge_base_id" {
1616
output "data_source_id" {
1717
description = "The Bedrock Agent's data source"
1818
value = module.bedrock.datasource_identifier
19-
}
20-
21-
# output "foundation_models" {
22-
# description = "The Bedrock Agent's foundation models"
23-
# value = data.aws_bedrock_foundation_models.test
24-
# }
19+
}

samples/bedrock-agent/variables.tf

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
variable "region" {
2+
type = string
3+
description = "AWS region to deploy the resources"
4+
default = "us-east-1"
5+
validation {
6+
condition = contains([
7+
"us-east-1", "us-west-2",
8+
"ap-southeast-1", "ap-southeast-2", "ap-northeast-1", "ap-south-1",
9+
"ca-central-1",
10+
"eu-central-1", "eu-west-1", "eu-west-2", "eu-west-3",
11+
"sa-east-1",
12+
], var.region)
13+
error_message = "Please use a region supporting Agents for Amazon Bedrock https://docs.aws.amazon.com/general/latest/gr/bedrock.html."
14+
}
15+
}
16+
17+
variable "architecture" {
18+
type = string
19+
description = "The runtime architecture"
20+
nullable = false
21+
default = "x86_64"
22+
validation {
23+
condition = contains(["x86_64", "arm64"], var.architecture)
24+
error_message = "The architecture must be either 'x86_64' or 'arm64'."
25+
}
26+
}
27+
28+
variable "foundation_model" {
29+
type = string
30+
description = "The foundation model to use for the agent"
31+
nullable = false
32+
default = "anthropic.claude-3-5-haiku-20241022-v1:0"
33+
validation {
34+
condition = contains(data.aws_bedrock_foundation_models.test.model_summaries[*].model_id, var.foundation_model)
35+
error_message = "The foundational model is not found"
36+
}
37+
}

0 commit comments

Comments
 (0)