Skip to content

Commit decdd8b

Browse files
fix: update bedrock module (#41)
* update bedrock module * bump aws-lambda-powertools * update time for deployment * powertools description * readme number of resources * add time to lambda and gutendex Bumps [aws-lambda-powertools](https://github.com/aws-powertools/powertools-lambda-python) from 2.43.1 to 3.3.0. - [Release notes](https://github.com/aws-powertools/powertools-lambda-python/releases) - [Changelog](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/CHANGELOG.md) - [Upgrade guide](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/docs/upgrade.md) - [Commits](aws-powertools/powertools-lambda-python@v2.43.1...v3.3.0) --- updated-dependencies: - dependency-name: aws-lambda-powertools dependency-type: direct:development update-type: version-update:semver-major ... --------- Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: Scott Schreckengaust <scottschreckengaust@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 57b0fba commit decdd8b

File tree

7 files changed

+37
-17
lines changed

7 files changed

+37
-17
lines changed

samples/bedrock-agent/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ _NOTE: The default architecture is `x86_64`, feel free to add `-var="architectur
110110
$ terraform apply
111111
```
112112
113-
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).
113+
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).
114114
115115
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.
116116
117117
```
118118
...
119119
120-
Apply complete! Resources: 27 added, 0 changed, 0 destroyed.
120+
Apply complete! Resources: 30 added, 0 changed, 0 destroyed.
121121
122122
Outputs:
123123

samples/bedrock-agent/lambda/action-group/gutendex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
def get_books_from_gutendex(n: int) -> dict:
1717
"""Return the count and first n books from the /books API."""
1818
api_url = "https://gutendex.com"
19-
response = requests.get(api_url + "/books", timeout=14) # keep a little less than the Lambda timeout
19+
response = requests.get(api_url + "/books", timeout=44) # keep a little less than the Lambda timeout
2020
response.raise_for_status()
2121
books = response.json()
2222
return {"count": books["count"], "books": books["results"][:n]}

samples/bedrock-agent/lambda/action-group/index.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020

2121
app = BedrockAgentResolver()
2222

23-
24-
@app.get("/top_books")
23+
@app.get(rule="/top_books", description="Get top books from gutendex")
2524
def get_top_books():
2625
return get_books_from_gutendex(5)
2726

samples/bedrock-agent/lambda/action-group/poetry.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/bedrock-agent/lambda/action-group/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ requests = "^2.32.0"
1111

1212

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

1616
[build-system]
1717
requires = ["poetry-core"]

samples/bedrock-agent/main.tf

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ provider "opensearch" {
1414
module "bedrock" {
1515
#checkov:skip=CKV_TF_1:Terraform registry has no ability to use a commit hash
1616
source = "aws-ia/bedrock/aws"
17-
version = "0.0.3"
17+
version = "0.0.4"
1818
create_kb = true
1919
create_default_kb = true
2020
create_agent = true
@@ -36,7 +36,7 @@ module "lambda" {
3636
handler = "index.handler"
3737
runtime = "python3.12"
3838
publish = true
39-
timeout = 15
39+
timeout = 45
4040
architectures = ["${var.architecture}", ]
4141
layers = ["arn:aws:lambda:${var.region}:017000801446:layer:AWSLambdaPowertoolsPythonV3-python312-${var.architecture}:4", ]
4242
source_path = [
@@ -46,3 +46,24 @@ module "lambda" {
4646
}
4747
]
4848
}
49+
50+
resource "aws_lambda_permission" "allow_bedrock_agent" {
51+
action = "lambda:InvokeFunction"
52+
function_name = module.lambda.lambda_function_arn
53+
principal = "bedrock.amazonaws.com"
54+
source_arn = module.bedrock.bedrock_agent[0].agent_arn
55+
}
56+
57+
resource "aws_iam_role_policy" "agent_policy" {
58+
policy = jsonencode({
59+
Version = "2012-10-17"
60+
Statement = [
61+
{
62+
Effect = "Allow"
63+
Action = "lambda:InvokeModel"
64+
Resource = module.lambda.lambda_function_arn
65+
}
66+
]
67+
})
68+
role = split("/", provider::aws::arn_parse(module.bedrock.bedrock_agent[0].agent_resource_role_arn).resource)[1]
69+
}

samples/bedrock-agent/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ variable "foundation_model" {
2929
type = string
3030
description = "The foundation model to use for the agent"
3131
nullable = false
32-
default = "anthropic.claude-3-5-haiku-20241022-v1:0"
32+
default = "anthropic.claude-3-haiku-20240307-v1:0"
3333
validation {
3434
condition = contains(data.aws_bedrock_foundation_models.test.model_summaries[*].model_id, var.foundation_model)
3535
error_message = "The foundational model is not found"

0 commit comments

Comments
 (0)