bedrock-agentcore-starter-toolkit 0.1.0__py3-none-any.whl → 0.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of bedrock-agentcore-starter-toolkit might be problematic. Click here for more details.
- bedrock_agentcore_starter_toolkit/cli/cli.py +3 -10
- bedrock_agentcore_starter_toolkit/cli/runtime/commands.py +52 -4
- bedrock_agentcore_starter_toolkit/cli/runtime/configuration_manager.py +20 -11
- bedrock_agentcore_starter_toolkit/notebook/runtime/bedrock_agentcore.py +53 -10
- bedrock_agentcore_starter_toolkit/operations/gateway/README.md +6 -6
- bedrock_agentcore_starter_toolkit/operations/gateway/create_role.py +11 -10
- bedrock_agentcore_starter_toolkit/operations/runtime/configure.py +21 -7
- bedrock_agentcore_starter_toolkit/operations/runtime/create_role.py +404 -0
- bedrock_agentcore_starter_toolkit/operations/runtime/launch.py +329 -53
- bedrock_agentcore_starter_toolkit/operations/runtime/models.py +4 -1
- bedrock_agentcore_starter_toolkit/services/codebuild.py +337 -0
- bedrock_agentcore_starter_toolkit/services/ecr.py +29 -0
- bedrock_agentcore_starter_toolkit/services/runtime.py +91 -1
- bedrock_agentcore_starter_toolkit/utils/logging_config.py +72 -0
- bedrock_agentcore_starter_toolkit/utils/runtime/entrypoint.py +3 -3
- bedrock_agentcore_starter_toolkit/utils/runtime/policy_template.py +74 -0
- bedrock_agentcore_starter_toolkit/utils/runtime/schema.py +12 -2
- bedrock_agentcore_starter_toolkit/utils/runtime/templates/Dockerfile.j2 +10 -25
- bedrock_agentcore_starter_toolkit/utils/runtime/templates/dockerignore.template +0 -1
- bedrock_agentcore_starter_toolkit/utils/runtime/templates/execution_role_policy.json.j2 +98 -0
- bedrock_agentcore_starter_toolkit/utils/runtime/templates/execution_role_trust_policy.json.j2 +21 -0
- {bedrock_agentcore_starter_toolkit-0.1.0.dist-info → bedrock_agentcore_starter_toolkit-0.1.2.dist-info}/METADATA +8 -8
- {bedrock_agentcore_starter_toolkit-0.1.0.dist-info → bedrock_agentcore_starter_toolkit-0.1.2.dist-info}/RECORD +27 -21
- {bedrock_agentcore_starter_toolkit-0.1.0.dist-info → bedrock_agentcore_starter_toolkit-0.1.2.dist-info}/WHEEL +0 -0
- {bedrock_agentcore_starter_toolkit-0.1.0.dist-info → bedrock_agentcore_starter_toolkit-0.1.2.dist-info}/entry_points.txt +0 -0
- {bedrock_agentcore_starter_toolkit-0.1.0.dist-info → bedrock_agentcore_starter_toolkit-0.1.2.dist-info}/licenses/LICENSE.txt +0 -0
- {bedrock_agentcore_starter_toolkit-0.1.0.dist-info → bedrock_agentcore_starter_toolkit-0.1.2.dist-info}/licenses/NOTICE.txt +0 -0
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
"""BedrockAgentCore CLI main module."""
|
|
2
2
|
|
|
3
|
-
import logging
|
|
4
|
-
|
|
5
3
|
import typer
|
|
6
|
-
from rich.logging import RichHandler
|
|
7
4
|
|
|
8
5
|
from ..cli.gateway.commands import create_mcp_gateway, create_mcp_gateway_target, gateway_app
|
|
9
|
-
from .
|
|
6
|
+
from ..utils.logging_config import setup_toolkit_logging
|
|
10
7
|
from .runtime.commands import configure_app, invoke, launch, status
|
|
11
8
|
|
|
12
9
|
app = typer.Typer(name="agentcore", help="BedrockAgentCore CLI", add_completion=False)
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
level="INFO",
|
|
17
|
-
format=FORMAT,
|
|
18
|
-
handlers=[RichHandler(show_time=False, show_path=False, show_level=False, console=console)],
|
|
19
|
-
)
|
|
11
|
+
# Setup centralized logging for CLI
|
|
12
|
+
setup_toolkit_logging(mode="cli")
|
|
20
13
|
|
|
21
14
|
# runtime
|
|
22
15
|
app.command("invoke")(invoke)
|
|
@@ -264,14 +264,18 @@ def launch(
|
|
|
264
264
|
),
|
|
265
265
|
local: bool = typer.Option(False, "--local", "-l", help="Run locally"),
|
|
266
266
|
push_ecr: bool = typer.Option(False, "--push-ecr", "-p", help="Build and push to ECR only (no deployment)"),
|
|
267
|
+
codebuild: bool = typer.Option(False, "--codebuild", "-cb", help="Use CodeBuild for ARM64 builds"),
|
|
268
|
+
auto_update_on_conflict: bool = typer.Option(
|
|
269
|
+
False, "--auto-update-on-conflict", help="Enable automatic update when agent already exists"
|
|
270
|
+
),
|
|
267
271
|
envs: List[str] = typer.Option( # noqa: B008
|
|
268
272
|
None, "--env", "-env", help="Environment variables for agent (format: KEY=VALUE)"
|
|
269
273
|
),
|
|
270
274
|
):
|
|
271
275
|
"""Launch Bedrock AgentCore locally or to cloud."""
|
|
272
276
|
# Validate mutually exclusive options
|
|
273
|
-
if local
|
|
274
|
-
_handle_error("Error: --local
|
|
277
|
+
if sum([local, push_ecr, codebuild]) > 1:
|
|
278
|
+
_handle_error("Error: --local, --push-ecr, and --codebuild cannot be used together")
|
|
275
279
|
|
|
276
280
|
config_path = Path.cwd() / ".bedrock_agentcore.yaml"
|
|
277
281
|
|
|
@@ -281,6 +285,8 @@ def launch(
|
|
|
281
285
|
mode = "local"
|
|
282
286
|
elif push_ecr:
|
|
283
287
|
mode = "push-ecr"
|
|
288
|
+
elif codebuild:
|
|
289
|
+
mode = "codebuild"
|
|
284
290
|
else:
|
|
285
291
|
mode = "cloud"
|
|
286
292
|
|
|
@@ -304,7 +310,9 @@ def launch(
|
|
|
304
310
|
agent_name=agent,
|
|
305
311
|
local=local,
|
|
306
312
|
push_ecr_only=push_ecr,
|
|
313
|
+
use_codebuild=codebuild,
|
|
307
314
|
env_vars=env_vars,
|
|
315
|
+
auto_update_on_conflict=auto_update_on_conflict,
|
|
308
316
|
)
|
|
309
317
|
|
|
310
318
|
# Handle result based on mode
|
|
@@ -336,6 +344,48 @@ def launch(
|
|
|
336
344
|
)
|
|
337
345
|
)
|
|
338
346
|
|
|
347
|
+
elif result.mode == "codebuild":
|
|
348
|
+
_print_success(f"CodeBuild completed: [cyan]{result.codebuild_id}[/cyan]")
|
|
349
|
+
_print_success(f"ARM64 image pushed to ECR: [cyan]{result.ecr_uri}:latest[/cyan]")
|
|
350
|
+
|
|
351
|
+
# Show deployment success panel
|
|
352
|
+
agent_name = result.tag.split(":")[0].replace("bedrock_agentcore-", "")
|
|
353
|
+
deploy_panel = (
|
|
354
|
+
f"[green]CodeBuild ARM64 Deployment Successful![/green]\n\n"
|
|
355
|
+
f"Agent Name: {agent_name}\n"
|
|
356
|
+
f"CodeBuild ID: [cyan]{result.codebuild_id}[/cyan]\n"
|
|
357
|
+
f"Agent ARN: [cyan]{result.agent_arn}[/cyan]\n"
|
|
358
|
+
f"ECR URI: [cyan]{result.ecr_uri}:latest[/cyan]\n\n"
|
|
359
|
+
f"ARM64 container deployed to Bedrock AgentCore.\n\n"
|
|
360
|
+
f"You can now check the status of your Bedrock AgentCore endpoint with:\n"
|
|
361
|
+
f"[cyan]agentcore status[/cyan]\n\n"
|
|
362
|
+
f"You can now invoke your Bedrock AgentCore endpoint with:\n"
|
|
363
|
+
f'[cyan]agentcore invoke \'{{"prompt": "Hello"}}\'[/cyan]'
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
# Add log information if we have agent_id
|
|
367
|
+
if result.agent_id:
|
|
368
|
+
from ...utils.runtime.logs import get_agent_log_paths, get_aws_tail_commands
|
|
369
|
+
|
|
370
|
+
runtime_logs, otel_logs = get_agent_log_paths(result.agent_id)
|
|
371
|
+
follow_cmd, since_cmd = get_aws_tail_commands(runtime_logs)
|
|
372
|
+
deploy_panel += (
|
|
373
|
+
f"\n\n📋 [cyan]Agent logs available at:[/cyan]\n"
|
|
374
|
+
f" {runtime_logs}\n"
|
|
375
|
+
f" {otel_logs}\n\n"
|
|
376
|
+
f"💡 [dim]Tail logs with:[/dim]\n"
|
|
377
|
+
f" {follow_cmd}\n"
|
|
378
|
+
f" {since_cmd}"
|
|
379
|
+
)
|
|
380
|
+
|
|
381
|
+
console.print(
|
|
382
|
+
Panel(
|
|
383
|
+
deploy_panel,
|
|
384
|
+
title="CodeBuild Deployment Complete",
|
|
385
|
+
border_style="green",
|
|
386
|
+
)
|
|
387
|
+
)
|
|
388
|
+
|
|
339
389
|
else: # cloud mode
|
|
340
390
|
_print_success(f"Image pushed to ECR: [cyan]{result.ecr_uri}:latest[/cyan]")
|
|
341
391
|
|
|
@@ -485,8 +535,6 @@ def status(
|
|
|
485
535
|
try:
|
|
486
536
|
if not verbose:
|
|
487
537
|
if "config" in status_json:
|
|
488
|
-
print(f"Getting Status for {status_json['config']['name']}")
|
|
489
|
-
|
|
490
538
|
if status_json["agent"] is None:
|
|
491
539
|
console.print(
|
|
492
540
|
Panel(
|
|
@@ -21,19 +21,25 @@ class ConfigurationManager:
|
|
|
21
21
|
project_config = load_config_if_exists(config_path)
|
|
22
22
|
self.existing_config = project_config.get_agent_config() if project_config else None
|
|
23
23
|
|
|
24
|
-
def prompt_execution_role(self) -> str:
|
|
25
|
-
"""Prompt for execution role
|
|
24
|
+
def prompt_execution_role(self) -> Optional[str]:
|
|
25
|
+
"""Prompt for execution role. Returns role name/ARN or None for auto-creation."""
|
|
26
26
|
console.print("\n🔐 [cyan]Execution Role[/cyan]")
|
|
27
|
-
console.print(
|
|
27
|
+
console.print(
|
|
28
|
+
"[dim]Press Enter to auto-create execution role, or provide execution role ARN/name to use existing[/dim]"
|
|
29
|
+
)
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
# Show existing config info but don't use as default
|
|
32
|
+
if self.existing_config and self.existing_config.aws.execution_role:
|
|
33
|
+
console.print(f"[dim]Previously configured: {self.existing_config.aws.execution_role}[/dim]")
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
_handle_error("Execution role is required")
|
|
35
|
+
role = _prompt_with_default("Execution role ARN/name (or press Enter to auto-create)", "")
|
|
34
36
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
if role:
|
|
38
|
+
_print_success(f"Using existing execution role: [dim]{role}[/dim]")
|
|
39
|
+
return role
|
|
40
|
+
else:
|
|
41
|
+
_print_success("Will auto-create execution role")
|
|
42
|
+
return None
|
|
37
43
|
|
|
38
44
|
def prompt_ecr_repository(self) -> tuple[Optional[str], bool]:
|
|
39
45
|
"""Prompt for ECR repository. Returns (repository, auto_create_flag)."""
|
|
@@ -42,8 +48,11 @@ class ConfigurationManager:
|
|
|
42
48
|
"[dim]Press Enter to auto-create ECR repository, or provide ECR Repository URI to use existing[/dim]"
|
|
43
49
|
)
|
|
44
50
|
|
|
45
|
-
|
|
46
|
-
|
|
51
|
+
# Show existing config info but don't use as default
|
|
52
|
+
if self.existing_config and self.existing_config.aws.ecr_repository:
|
|
53
|
+
console.print(f"[dim]Previously configured: {self.existing_config.aws.ecr_repository}[/dim]")
|
|
54
|
+
|
|
55
|
+
response = _prompt_with_default("ECR Repository URI (or press Enter to auto-create)", "")
|
|
47
56
|
|
|
48
57
|
if response:
|
|
49
58
|
_print_success(f"Using existing ECR repository: [dim]{response}[/dim]")
|
|
@@ -12,15 +12,15 @@ from ...operations.runtime import (
|
|
|
12
12
|
validate_agent_name,
|
|
13
13
|
)
|
|
14
14
|
from ...operations.runtime.models import ConfigureResult, LaunchResult, StatusResult
|
|
15
|
+
|
|
16
|
+
# Setup centralized logging for SDK usage (notebooks, scripts, imports)
|
|
17
|
+
from ...utils.logging_config import setup_toolkit_logging
|
|
15
18
|
from ...utils.runtime.entrypoint import parse_entrypoint
|
|
16
19
|
|
|
17
|
-
|
|
20
|
+
setup_toolkit_logging(mode="sdk")
|
|
21
|
+
|
|
22
|
+
# Configure logger for this module
|
|
18
23
|
log = logging.getLogger(__name__)
|
|
19
|
-
if not log.handlers:
|
|
20
|
-
handler = logging.StreamHandler()
|
|
21
|
-
handler.setFormatter(logging.Formatter("%(message)s"))
|
|
22
|
-
log.addHandler(handler)
|
|
23
|
-
log.setLevel(logging.INFO)
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
class Runtime:
|
|
@@ -34,13 +34,14 @@ class Runtime:
|
|
|
34
34
|
def configure(
|
|
35
35
|
self,
|
|
36
36
|
entrypoint: str,
|
|
37
|
-
execution_role: str,
|
|
37
|
+
execution_role: Optional[str] = None,
|
|
38
38
|
agent_name: Optional[str] = None,
|
|
39
39
|
requirements: Optional[List[str]] = None,
|
|
40
40
|
requirements_file: Optional[str] = None,
|
|
41
41
|
ecr_repository: Optional[str] = None,
|
|
42
42
|
container_runtime: Optional[str] = None,
|
|
43
43
|
auto_create_ecr: bool = True,
|
|
44
|
+
auto_create_execution_role: bool = False,
|
|
44
45
|
authorizer_configuration: Optional[Dict[str, Any]] = None,
|
|
45
46
|
region: Optional[str] = None,
|
|
46
47
|
protocol: Optional[Literal["HTTP", "MCP"]] = None,
|
|
@@ -50,13 +51,14 @@ class Runtime:
|
|
|
50
51
|
Args:
|
|
51
52
|
entrypoint: Path to Python file with optional Bedrock AgentCore name
|
|
52
53
|
(e.g., "handler.py" or "handler.py:bedrock_agentcore")
|
|
53
|
-
execution_role: AWS IAM execution role ARN or name
|
|
54
|
+
execution_role: AWS IAM execution role ARN or name (optional if auto_create_execution_role=True)
|
|
54
55
|
agent_name: name of the agent
|
|
55
56
|
requirements: Optional list of requirements to generate requirements.txt
|
|
56
57
|
requirements_file: Optional path to existing requirements file
|
|
57
58
|
ecr_repository: Optional ECR repository URI
|
|
58
59
|
container_runtime: Optional container runtime (docker/podman)
|
|
59
60
|
auto_create_ecr: Whether to auto-create ECR repository
|
|
61
|
+
auto_create_execution_role: Whether to auto-create execution role (makes execution_role optional)
|
|
60
62
|
authorizer_configuration: JWT authorizer configuration dictionary
|
|
61
63
|
region: AWS region for deployment
|
|
62
64
|
protocol: agent server protocol, must be either HTTP or MCP
|
|
@@ -75,6 +77,10 @@ class Runtime:
|
|
|
75
77
|
if not valid:
|
|
76
78
|
raise ValueError(error)
|
|
77
79
|
|
|
80
|
+
# Validate execution role configuration
|
|
81
|
+
if not execution_role and not auto_create_execution_role:
|
|
82
|
+
raise ValueError("Must provide either 'execution_role' or set 'auto_create_execution_role=True'")
|
|
83
|
+
|
|
78
84
|
# Update our name if not already set
|
|
79
85
|
if not self.name:
|
|
80
86
|
self.name = agent_name
|
|
@@ -99,6 +105,7 @@ class Runtime:
|
|
|
99
105
|
result = configure_bedrock_agentcore(
|
|
100
106
|
agent_name=agent_name,
|
|
101
107
|
entrypoint_path=Path(file_path),
|
|
108
|
+
auto_create_execution_role=auto_create_execution_role,
|
|
102
109
|
execution_role=execution_role,
|
|
103
110
|
ecr_repository=ecr_repository,
|
|
104
111
|
container_runtime=container_runtime,
|
|
@@ -113,12 +120,21 @@ class Runtime:
|
|
|
113
120
|
log.info("Bedrock AgentCore configured: %s", self._config_path)
|
|
114
121
|
return result
|
|
115
122
|
|
|
116
|
-
def launch(
|
|
123
|
+
def launch(
|
|
124
|
+
self,
|
|
125
|
+
local: bool = False,
|
|
126
|
+
push_ecr: bool = False,
|
|
127
|
+
use_codebuild: bool = False,
|
|
128
|
+
auto_update_on_conflict: bool = False,
|
|
129
|
+
env_vars: Optional[Dict] = None,
|
|
130
|
+
) -> LaunchResult:
|
|
117
131
|
"""Launch Bedrock AgentCore from notebook.
|
|
118
132
|
|
|
119
133
|
Args:
|
|
120
134
|
local: Whether to build for local execution only
|
|
121
135
|
push_ecr: Whether to push to ECR only (no deployment)
|
|
136
|
+
use_codebuild: Whether to use CodeBuild for ARM64 builds (cloud deployment only)
|
|
137
|
+
auto_update_on_conflict: Whether to automatically update resources on conflict (default: False)
|
|
122
138
|
env_vars: environment variables for agent container
|
|
123
139
|
|
|
124
140
|
Returns:
|
|
@@ -127,7 +143,19 @@ class Runtime:
|
|
|
127
143
|
if not self._config_path:
|
|
128
144
|
raise ValueError("Must configure before launching. Call .configure() first.")
|
|
129
145
|
|
|
130
|
-
|
|
146
|
+
# Validate mutually exclusive options
|
|
147
|
+
exclusive_options = [local, push_ecr, use_codebuild]
|
|
148
|
+
if sum(exclusive_options) > 1:
|
|
149
|
+
raise ValueError("Only one of 'local', 'push_ecr', or 'use_codebuild' can be True")
|
|
150
|
+
|
|
151
|
+
result = launch_bedrock_agentcore(
|
|
152
|
+
self._config_path,
|
|
153
|
+
local=local,
|
|
154
|
+
push_ecr_only=push_ecr,
|
|
155
|
+
use_codebuild=use_codebuild,
|
|
156
|
+
auto_update_on_conflict=auto_update_on_conflict,
|
|
157
|
+
env_vars=env_vars,
|
|
158
|
+
)
|
|
131
159
|
|
|
132
160
|
if result.mode == "cloud":
|
|
133
161
|
log.info("Deployed to cloud: %s", result.agent_arn)
|
|
@@ -135,6 +163,21 @@ class Runtime:
|
|
|
135
163
|
if result.agent_id:
|
|
136
164
|
from ...utils.runtime.logs import get_agent_log_paths, get_aws_tail_commands
|
|
137
165
|
|
|
166
|
+
runtime_logs, otel_logs = get_agent_log_paths(result.agent_id)
|
|
167
|
+
follow_cmd, since_cmd = get_aws_tail_commands(runtime_logs)
|
|
168
|
+
log.info("🔍 Agent logs available at:")
|
|
169
|
+
log.info(" %s", runtime_logs)
|
|
170
|
+
log.info(" %s", otel_logs)
|
|
171
|
+
log.info("💡 Tail logs with: %s", follow_cmd)
|
|
172
|
+
log.info("💡 Or view recent logs: %s", since_cmd)
|
|
173
|
+
elif result.mode == "codebuild":
|
|
174
|
+
log.info("Built with CodeBuild: %s", result.codebuild_id)
|
|
175
|
+
log.info("Deployed to cloud: %s", result.agent_arn)
|
|
176
|
+
log.info("ECR image: %s", result.ecr_uri)
|
|
177
|
+
# Show log information for CodeBuild deployments
|
|
178
|
+
if result.agent_id:
|
|
179
|
+
from ...utils.runtime.logs import get_agent_log_paths, get_aws_tail_commands
|
|
180
|
+
|
|
138
181
|
runtime_logs, otel_logs = get_agent_log_paths(result.agent_id)
|
|
139
182
|
follow_cmd, since_cmd = get_aws_tail_commands(runtime_logs)
|
|
140
183
|
log.info("🔍 Agent logs available at:")
|
|
@@ -18,16 +18,16 @@ agentcore create_mcp_gateway \
|
|
|
18
18
|
|
|
19
19
|
# Create a Gateway Target with predefined smithy model
|
|
20
20
|
agentcore create_mcp_gateway_target \
|
|
21
|
-
--region us-
|
|
22
|
-
--gateway-arn arn:aws:bedrock-agentcore:us-
|
|
21
|
+
--region us-west-2 \
|
|
22
|
+
--gateway-arn arn:aws:bedrock-agentcore:us-west-2:123:gateway/gateway-id \
|
|
23
23
|
--gateway-url https://gateway-id.gateway.bedrock-agentcore.us-west-2.amazonaws.com/mcp \
|
|
24
24
|
--role-arn arn:aws:iam::123:role/BedrockAgentCoreGatewayRole \
|
|
25
25
|
--target-type smithyModel
|
|
26
26
|
|
|
27
27
|
# Create a Gateway Target with OpenAPI target (OAuth with API Key)
|
|
28
28
|
agentcore create_mcp_gateway_target \
|
|
29
|
-
--region us-
|
|
30
|
-
--gateway-arn arn:aws:bedrock-agentcore:us-
|
|
29
|
+
--region us-west-2 \
|
|
30
|
+
--gateway-arn arn:aws:bedrock-agentcore:us-west-2:123:gateway/gateway-id \
|
|
31
31
|
--gateway-url https://gateway-id.gateway.bedrock-agentcore.us-west-2.amazonaws.com/mcp \
|
|
32
32
|
--role-arn arn:aws:iam::123:role/BedrockAgentCoreGatewayRole \
|
|
33
33
|
--target-type openApiSchema \
|
|
@@ -36,8 +36,8 @@ agentcore create_mcp_gateway_target \
|
|
|
36
36
|
|
|
37
37
|
# Create a Gateway Target with OpenAPI target (OAuth with credential provider)
|
|
38
38
|
agentcore create_mcp_gateway_target \
|
|
39
|
-
--region us-
|
|
40
|
-
--gateway-arn arn:aws:bedrock-agentcore:us-
|
|
39
|
+
--region us-west-2 \
|
|
40
|
+
--gateway-arn arn:aws:bedrock-agentcore:us-west-2:123:gateway/gateway-id \
|
|
41
41
|
--gateway-url https://gateway-id.gateway.bedrock-agentcore.us-west-2.amazonaws.com/mcp \
|
|
42
42
|
--role-arn arn:aws:iam::123:role/BedrockAgentCoreGatewayRole \
|
|
43
43
|
--target-type openApiSchema \
|
|
@@ -43,17 +43,18 @@ def create_gateway_execution_role(
|
|
|
43
43
|
|
|
44
44
|
return role["Role"]["Arn"]
|
|
45
45
|
|
|
46
|
-
except iam.exceptions.EntityAlreadyExistsException:
|
|
47
|
-
try:
|
|
48
|
-
role = iam.get_role(RoleName=role_name)
|
|
49
|
-
logger.info("✓ Role already exists: %s", role["Role"]["Arn"])
|
|
50
|
-
return role["Role"]["Arn"]
|
|
51
|
-
except ClientError as e:
|
|
52
|
-
logger.error("Error getting existing role: %s", e)
|
|
53
|
-
raise
|
|
54
46
|
except ClientError as e:
|
|
55
|
-
|
|
56
|
-
|
|
47
|
+
if e.response["Error"]["Code"] == "EntityAlreadyExists":
|
|
48
|
+
try:
|
|
49
|
+
role = iam.get_role(RoleName=role_name)
|
|
50
|
+
logger.info("✓ Role already exists: %s", role["Role"]["Arn"])
|
|
51
|
+
return role["Role"]["Arn"]
|
|
52
|
+
except ClientError as get_error:
|
|
53
|
+
logger.error("Error getting existing role: %s", get_error)
|
|
54
|
+
raise
|
|
55
|
+
else:
|
|
56
|
+
logger.error("Error creating role: %s", e)
|
|
57
|
+
raise
|
|
57
58
|
|
|
58
59
|
|
|
59
60
|
def _attach_policy(
|
|
@@ -28,6 +28,7 @@ def configure_bedrock_agentcore(
|
|
|
28
28
|
ecr_repository: Optional[str] = None,
|
|
29
29
|
container_runtime: Optional[str] = None,
|
|
30
30
|
auto_create_ecr: bool = True,
|
|
31
|
+
auto_create_execution_role: bool = True,
|
|
31
32
|
enable_observability: bool = True,
|
|
32
33
|
requirements_file: Optional[str] = None,
|
|
33
34
|
authorizer_configuration: Optional[Dict[str, Any]] = None,
|
|
@@ -40,10 +41,11 @@ def configure_bedrock_agentcore(
|
|
|
40
41
|
Args:
|
|
41
42
|
agent_name: name of the agent,
|
|
42
43
|
entrypoint_path: Path to the entrypoint file
|
|
43
|
-
execution_role: AWS execution role ARN or name
|
|
44
|
+
execution_role: AWS execution role ARN or name (auto-created if not provided)
|
|
44
45
|
ecr_repository: ECR repository URI
|
|
45
46
|
container_runtime: Container runtime to use
|
|
46
47
|
auto_create_ecr: Whether to auto-create ECR repository
|
|
48
|
+
auto_create_execution_role: Whether to auto-create execution role if not provided
|
|
47
49
|
enable_observability: Whether to enable observability
|
|
48
50
|
requirements_file: Path to requirements file
|
|
49
51
|
authorizer_configuration: JWT authorizer configuration dictionary
|
|
@@ -84,15 +86,26 @@ def configure_bedrock_agentcore(
|
|
|
84
86
|
log.debug("Initializing container runtime with: %s", container_runtime or "default")
|
|
85
87
|
runtime = ContainerRuntime(container_runtime)
|
|
86
88
|
|
|
87
|
-
# Handle execution role ARN
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
# Handle execution role - convert to ARN if provided, otherwise use auto-create setting
|
|
90
|
+
execution_role_arn = None
|
|
91
|
+
execution_role_auto_create = auto_create_execution_role
|
|
92
|
+
|
|
93
|
+
if execution_role:
|
|
94
|
+
# User provided a role - convert to ARN format if needed
|
|
95
|
+
if execution_role.startswith("arn:aws:iam::"):
|
|
96
|
+
execution_role_arn = execution_role
|
|
97
|
+
else:
|
|
98
|
+
execution_role_arn = f"arn:aws:iam::{account_id}:role/{execution_role}"
|
|
99
|
+
|
|
90
100
|
if verbose:
|
|
91
|
-
log.debug("
|
|
101
|
+
log.debug("Using execution role: %s", execution_role_arn)
|
|
92
102
|
else:
|
|
93
|
-
|
|
103
|
+
# No role provided - use auto_create_execution_role parameter
|
|
94
104
|
if verbose:
|
|
95
|
-
|
|
105
|
+
if execution_role_auto_create:
|
|
106
|
+
log.debug("Execution role will be auto-created during launch")
|
|
107
|
+
else:
|
|
108
|
+
log.debug("No execution role provided and auto-create disabled")
|
|
96
109
|
|
|
97
110
|
# Generate Dockerfile and .dockerignore
|
|
98
111
|
bedrock_agentcore_name = None
|
|
@@ -166,6 +179,7 @@ def configure_bedrock_agentcore(
|
|
|
166
179
|
container_runtime=runtime.runtime,
|
|
167
180
|
aws=AWSConfig(
|
|
168
181
|
execution_role=execution_role_arn,
|
|
182
|
+
execution_role_auto_create=execution_role_auto_create,
|
|
169
183
|
account=account_id,
|
|
170
184
|
region=region,
|
|
171
185
|
ecr_repository=ecr_repository,
|