Skip to content

Commit ec7880e

Browse files
sundargthbSundar Raghavan
andauthored
fix(deps): restrict pydantic to versions below 2.41.3 (#280)
* fix(deps): restrict pydantic to versions below 2.41.3 * fix integration test to use auto create for execution role --------- Co-authored-by: Sundar Raghavan <sdraghav@amazon.com>
1 parent 19203e9 commit ec7880e

File tree

4 files changed

+76
-4
lines changed

4 files changed

+76
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ dependencies = [
3333
"httpx>=0.28.1",
3434
"jinja2>=3.1.6",
3535
"prompt-toolkit>=3.0.51",
36-
"pydantic>=2.0.0,<3.0.0",
36+
"pydantic>=2.0.0,<2.41.3",
3737
"urllib3>=1.26.0",
3838
"pyyaml>=6.0.2",
3939
"requests>=2.25.0",

tests_integ/cli/runtime/test_simple_agent.py

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import json
12
import logging
23
import textwrap
34
from typing import List
45

6+
import boto3
57
from click.testing import Result
68

79
from tests_integ.cli.runtime.base_test import BaseCLIRuntimeTest, CommandInvocation
@@ -17,6 +19,12 @@ class TestSimpleAgent(BaseCLIRuntimeTest):
1719
"""
1820

1921
def setup(self):
22+
# Extract role name from ARN if provided
23+
if TEST_ROLE:
24+
self.role_name = TEST_ROLE.split("/")[-1]
25+
else:
26+
self.role_name = None
27+
2028
self.agent_file = "agent.py"
2129
self.requirements_file = "requirements.txt"
2230

@@ -43,6 +51,64 @@ async def agent_invocation(payload):
4351
""").strip()
4452
file.write(content)
4553

54+
def _setup_role_trust_policy(self):
55+
"""
56+
Ensure the IAM role has the required trust relationship with Bedrock.
57+
"""
58+
try:
59+
iam_client = boto3.client("iam")
60+
61+
# Get current trust policy
62+
response = iam_client.get_role(RoleName=self.role_name)
63+
current_policy = response["Role"]["AssumeRolePolicyDocument"]
64+
65+
# Check if bedrock is already a trusted service
66+
bedrock_trusted = False
67+
for statement in current_policy.get("Statement", []):
68+
principal = statement.get("Principal", {})
69+
service = principal.get("Service", [])
70+
if isinstance(service, str):
71+
service = [service]
72+
if "bedrock.amazonaws.com" in service:
73+
bedrock_trusted = True
74+
break
75+
76+
# Add bedrock trust if needed
77+
if not bedrock_trusted:
78+
logger.info("Adding bedrock.amazonaws.com to trust policy for role %s", self.role_name)
79+
80+
# Copy the existing policy and add bedrock
81+
if len(current_policy.get("Statement", [])) > 0:
82+
# Add to existing policy
83+
new_statement = {
84+
"Effect": "Allow",
85+
"Principal": {"Service": "bedrock.amazonaws.com"},
86+
"Action": "sts:AssumeRole",
87+
}
88+
current_policy["Statement"].append(new_statement)
89+
else:
90+
# Create new policy
91+
current_policy = {
92+
"Version": "2012-10-17",
93+
"Statement": [
94+
{
95+
"Effect": "Allow",
96+
"Principal": {"Service": "bedrock.amazonaws.com"},
97+
"Action": "sts:AssumeRole",
98+
}
99+
],
100+
}
101+
102+
# Update the role
103+
iam_client.update_assume_role_policy(RoleName=self.role_name, PolicyDocument=json.dumps(current_policy))
104+
logger.info("Updated trust policy for role %s", self.role_name)
105+
else:
106+
logger.info("Role %s already trusts bedrock.amazonaws.com", self.role_name)
107+
108+
except Exception as e:
109+
logger.error("Error updating role trust policy: %s", str(e))
110+
raise
111+
46112
def get_command_invocations(self) -> List[CommandInvocation]:
47113
configure_invocation = CommandInvocation(
48114
command=[
@@ -85,7 +151,13 @@ def validate_configure(self, result: Result):
85151

86152
assert "Configuration Success" in output
87153
assert "Agent Name: agent" in output
88-
assert TEST_ROLE in output
154+
155+
# Handle both explicit role and auto-create
156+
if TEST_ROLE:
157+
assert TEST_ROLE in output
158+
else:
159+
assert "Auto-create" in output or "Execution Role:" in output
160+
89161
assert "Authorization: IAM" in output
90162
assert ".bedrock_agentcore.yaml" in output
91163

tests_integ/utils/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import os
22

3-
TEST_ROLE = os.getenv("AGENTCORE_TEST_ROLE", default="Admin")
3+
TEST_ROLE = None
44
TEST_ECR = os.getenv("AGENTCORE_TEST_ECR", default="auto")

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)