fix(import): harden Bedrock Agent runtime imports - #2153
Conversation
|
Claude Security Review: no high-confidence findings. (run) |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## refactor #2153 +/- ##
============================================
+ Coverage 97.22% 97.37% +0.14%
============================================
Files 507 507
Lines 33809 33841 +32
============================================
+ Hits 32872 32951 +79
+ Misses 937 890 -47 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
AgentCore Harness Review
Verdict: Looks good
Reviewed the eight fixes against bedrockAgent.ts, importBedrockAgent.ts, templates/runtime.ts, and the Python proxy template. The changes are well-scoped, all failure modes are covered by tests at real I/O boundaries (control-plane client injection, in-memory describeBedrockAgent fakes), and the live-lifecycle validation in the description confirms the caller-owned-role and long-session-id paths end-to-end.
A few things I looked at and am comfortable with:
- Session-id normalization (
main.py): 64-char SHA-256 hex matches the^[0-9A-Za-z._:-]{2,100}$pattern, non-string/empty inputs correctly fall through to a fresh UUID, and emptycontext.session_idshort-circuits topayload.get("sessionId")as intended. - Response validation (
bedrockAgent.ts):agent.agentId/agent.agentNameare now checked beforegetAgentAlias, and the alias response is cross-checked against the requested IDs, which is what the description promised. additionalPoliciesomission withexecutionRoleArn(templates/runtime.ts): the generatedbedrock-agent-policy.jsonfile is preserved for the user to attach manually, and the README template branches onusesExistingExecutionRoleto match — I traced both branches throughimportBedrockAgentResolverand the rendered README.- Protocol pre-check in
add/runtime/index.tscorrectly runs beforeresolveImportBedrockAgentInput, so--protocol MCPno longer triggers a Bedrock describe call (verified by the newrejects a non-HTTP protocol before describing the agenttest).
One minor observation, not blocking: bedrockAgent.ts switched from await import("@aws-sdk/client-bedrock-agent") to a top-level static import. This is consistent with src/core/invokeRuntime.ts (which also statically imports an AWS SDK command class on a hot handler path), so it's aligned with existing convention — just noting the deviation from the previous lazy-load pattern in case CLI cold-start latency is being tracked.
Nice work.
Context
PR #2146 added
project create --type importandproject add runtime --type importto wrap an existing Amazon Bedrock Agent in an AgentCore Runtime proxy. Post-merge testing found eight defects in the import path. This PR fixes those defects without changing--type create.Bugs fixed
Service discovery and readiness
Malformed
GetAgentresponses were validated too late. The CLI requested the alias before validating the agent response. An alias-not-found response therefore replaced the earlier malformed-agent error. The control-plane client now validates required agent identity fields before requesting the alias, then validates that the returned alias belongs to the requested agent and alias ID.Readiness checked the mutable agent draft instead of the selected alias. The generated proxy invokes
agentIdplusagentAliasId, but the CLI warned onagentStatus. It now warns whenagentAliasStatusis notPREPAREDand does not warn when a prepared alias points to a version while the mutable draft isNOT_PREPARED.Four predecessor-supported regions were rejected. The import allowlist now includes
ap-southeast-2,eu-central-2,eu-west-2, andeu-west-3.Runtime configuration
Non-HTTP imports called AWS before local validation.
--type import --protocol MCPpreviously described the agent before the template rejected the protocol. The handler now rejects non-HTTP protocols before any Bedrock Agent API call.Caller-owned roles appeared to receive a policy that CDK did not attach. AgentCore CDK imports
executionRoleArnroles without modifying them, but the generated runtime still listedbedrock-agent-policy.jsoninadditionalPolicies. The CLI now:bedrock:InvokeAgenton the selected alias;additionalPolicieswhenexecutionRoleArnis supplied; andbedrock-agent-policy.jsonas the exact document the user must attach, with matching generated README guidance.Generated proxy runtime
Valid non-object JSON payloads crashed. Payloads such as
[]reachedpayload.getand raisedAttributeError. The proxy now returns a controlled validation response and does not call Bedrock.AgentCore session IDs were forwarded without adapting the Bedrock Agent contract. AgentCore Runtime accepts session IDs longer than the Bedrock Agent maximum of 100 characters. The proxy now preserves IDs that already satisfy the Bedrock pattern and deterministically hashes incompatible IDs to a 64-character value. This preserves multi-turn continuity for repeated AgentCore session IDs.
Synchronous boto3 work blocked the async runtime loop. The async entrypoint called
invoke_agentand iterated its event stream synchronously. Both operations now run throughasyncio.to_thread, while the response remains streamed one event at a time.Validation
Automated
bun test src/core/project/bedrockAgent.test.ts src/handlers/project/importBedrockAgent.test.ts src/handlers/project/add/runtime/index.test.ts src/handlers/project/project.test.tsbun test srcbun run typecheckbun run lint:checkbun run format:checkbun run buildExecutable Python proxy probe
The generated proxy template was executed with stubbed AgentCore and boto3 modules:
Live AWS lifecycle
Using
AWS_PROFILE=deployin account603141041947, regionus-east-1:NFGNHKMZXKand aliasWABJLTQRXC;bedrock:InvokeAgentpolicy;AgentCore-ImportFix0831-defaulttoCREATE_COMPLETE;The capital of France is Paris.;LONG_SESSION_OKinstead of a Bedrock validation error;[]returnedInvalid payload; expected a JSON object with a non-empty 'prompt' field.instead ofAttributeError; andThe stack, AgentCore Runtime, Bedrock Agent alias, Bedrock Agent, inline policy, and IAM role were deleted after testing. No test AWS resources remain.
Out of scope
--type createbehavior is intentionally unchanged. Existing project-manager dependency-install rollback behavior and the runtime invoke HTTP-200 error-event contract are also unchanged because they predate Bedrock Agent import.