Skip to content

fix: update bedrock module #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions samples/bedrock-agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ _NOTE: The default architecture is `x86_64`, feel free to add `-var="architectur
$ terraform apply
```

The command above will deploy in your AWS account. With the default configuration of this sample, the observed deployment time was ~381 seconds (6.5 minutes).
The command above will deploy in your AWS account. With the default configuration of this sample, the observed deployment time was ~451 seconds (7.5 minutes).

To protect you against unintended changes that affect your security posture, the Terraform prompts you to approve before deploying them. You will need to answer "yes" to get the solution deployed.

```
...

Apply complete! Resources: 27 added, 0 changed, 0 destroyed.
Apply complete! Resources: 30 added, 0 changed, 0 destroyed.

Outputs:

Expand Down
2 changes: 1 addition & 1 deletion samples/bedrock-agent/lambda/action-group/gutendex.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
def get_books_from_gutendex(n: int) -> dict:
"""Return the count and first n books from the /books API."""
api_url = "https://gutendex.com"
response = requests.get(api_url + "/books", timeout=14) # keep a little less than the Lambda timeout
response = requests.get(api_url + "/books", timeout=44) # keep a little less than the Lambda timeout
response.raise_for_status()
books = response.json()
return {"count": books["count"], "books": books["results"][:n]}
3 changes: 1 addition & 2 deletions samples/bedrock-agent/lambda/action-group/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

app = BedrockAgentResolver()


@app.get("/top_books")
@app.get(rule="/top_books", description="Get top books from gutendex")
def get_top_books():
return get_books_from_gutendex(5)

Expand Down
16 changes: 8 additions & 8 deletions samples/bedrock-agent/lambda/action-group/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion samples/bedrock-agent/lambda/action-group/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ requests = "^2.32.0"


[tool.poetry.group.dev.dependencies]
aws-lambda-powertools = "^2.32.0"
aws-lambda-powertools = "^3.3.0"

[build-system]
requires = ["poetry-core"]
Expand Down
25 changes: 23 additions & 2 deletions samples/bedrock-agent/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ provider "opensearch" {
module "bedrock" {
#checkov:skip=CKV_TF_1:Terraform registry has no ability to use a commit hash
source = "aws-ia/bedrock/aws"
version = "0.0.3"
version = "0.0.4"
create_kb = true
create_default_kb = true
create_agent = true
Expand All @@ -36,7 +36,7 @@ module "lambda" {
handler = "index.handler"
runtime = "python3.12"
publish = true
timeout = 15
timeout = 45
architectures = ["${var.architecture}", ]
layers = ["arn:aws:lambda:${var.region}:017000801446:layer:AWSLambdaPowertoolsPythonV3-python312-${var.architecture}:4", ]
source_path = [
Expand All @@ -46,3 +46,24 @@ module "lambda" {
}
]
}

resource "aws_lambda_permission" "allow_bedrock_agent" {
action = "lambda:InvokeFunction"
function_name = module.lambda.lambda_function_arn
principal = "bedrock.amazonaws.com"
source_arn = module.bedrock.bedrock_agent[0].agent_arn
}

resource "aws_iam_role_policy" "agent_policy" {
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = "lambda:InvokeModel"
Resource = module.lambda.lambda_function_arn
}
]
})
role = split("/", provider::aws::arn_parse(module.bedrock.bedrock_agent[0].agent_resource_role_arn).resource)[1]
}
2 changes: 1 addition & 1 deletion samples/bedrock-agent/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ variable "foundation_model" {
type = string
description = "The foundation model to use for the agent"
nullable = false
default = "anthropic.claude-3-5-haiku-20241022-v1:0"
default = "anthropic.claude-3-haiku-20240307-v1:0"
validation {
condition = contains(data.aws_bedrock_foundation_models.test.model_summaries[*].model_id, var.foundation_model)
error_message = "The foundational model is not found"
Expand Down
Loading