Commit 2df1387
authored
feat: add gateway import command with executionRoleArn support (#855)
* feat: add gateway import command and unhide import from TUI
Add `agentcore import gateway --arn <arn>` to import existing AWS gateways
(with all targets) into a local CLI project. Also remove import from the
HIDDEN_FROM_TUI list so it appears in the interactive TUI.
- Add AWS SDK wrappers for gateway/target list/get APIs
- Add import-gateway.ts with multi-resource CFN import support
- Add resourceName schema field to preserve actual AWS gateway name during import
- Register gateway in TUI ImportSelectScreen and ImportProgressScreen
- Extend ARN pattern, deployed state, and CFN constants for gateway type
* fix: expand ARN input to show full resource ARN and add gateway support
The ARN text input was truncating long ARNs. Use the expandable prop to
wrap text across multiple lines. Also add gateway to the ARN validation
pattern and resource type labels.
* refactor: remove --name and --yes flags from import gateway command
Remove --name (confusing local rename) and --yes (no prompts to confirm)
from the gateway import command. The gateway's AWS name is used directly.
* feat: add e2e tests for import gateway command
Add end-to-end tests that create a real AWS gateway with an MCP server
target, import it via `agentcore import gateway --arn`, and verify the
resulting agentcore.json fields and deployed-state.json entries.
New files:
- e2e-tests/fixtures/import/setup_gateway.py: creates gateway + target
- e2e-tests/fixtures/import/common.py: gateway wait helpers
- e2e-tests/fixtures/import/cleanup_resources.py: gateway cleanup
Constraint: Tests follow the existing import-resources.test.ts pattern
Confidence: high
Scope-risk: narrow
* chore: gitignore bugbash-resources.json and .omc/
* feat: preserve gateway executionRoleArn during import
Extract roleArn from the AWS GetGateway response and map it to
executionRoleArn in agentcore.json. On deploy, CDK uses
iam.Role.fromRoleArn() instead of creating a new role, keeping the
original permissions intact.
Constraint: imported roles use mutable: false so CDK cannot modify them
Rejected: always create new role | breaks permissions on re-import
Confidence: high
Scope-risk: narrow
* refactor: export internal gateway import functions for unit testing
Add @internal exports for toGatewayTargetSpec, resolveOutboundAuth,
toGatewaySpec, and buildCredentialArnMap to enable direct unit testing
of the pure mapping functions in import-gateway.ts.
Confidence: high
Scope-risk: narrow
* test: add unit tests for mcpServer target mapping and credential resolution
Bugbash coverage for toGatewayTargetSpec and resolveOutboundAuth:
- mcpServer with no auth, OAuth, and API_KEY credentials
- Credential resolution warnings when ARNs not in project
- Targets with no MCP configuration
- OAuth scopes pass-through and empty scopes omission
8 tests, all passing.
Confidence: high
Scope-risk: narrow
* test: add unit tests for apiGateway, openApiSchema, smithyModel, lambda target mapping
Bugbash coverage for toGatewayTargetSpec non-mcpServer target types:
- apiGateway: restApiId, stage, toolFilters, toolOverrides mapping
- openApiSchema: S3 URI mapping, missing URI warning
- smithyModel: S3 URI mapping, missing URI warning
- lambda: S3 tool schema to lambdaFunctionArn mapping, missing ARN,
inline-only schema warning, progress messages
- Unrecognized target type warning
13 tests, all passing.
Confidence: high
Scope-risk: narrow
* test: add unit tests for toGatewaySpec gateway-level field mapping
Bugbash coverage for toGatewaySpec AWS-to-CLI schema mapping:
- Authorizer types: NONE, AWS_IAM, CUSTOM_JWT with all JWT fields
- CUSTOM_JWT customClaims with full claim structure
- Semantic search: SEMANTIC/KEYWORD/missing protocolConfiguration
- Exception level: DEBUG/undefined/other values
- Policy engine: ARN name extraction, mode preservation
- Optional fields: resourceName, description, tags, executionRoleArn
- Edge cases: empty tags object omitted, empty JWT arrays omitted
23 tests, all passing.
Confidence: high
Scope-risk: narrow
* test: add unit tests for handleImportGateway full flow validation
Bugbash coverage for the main gateway import flow:
- Happy path: successful import with --arn, config written, result verified
- Rollback: pipeline failure restores original config, noResources error
- Duplicate detection: name collision, resource ID already tracked
- Name validation: invalid name regex, --name override preserves resourceName
- Auto-select: single gateway auto-selected, multiple gateways error, no gateways error
- Target mapping: skipped targets warning, non-READY gateway continues
12 tests, all passing.
Confidence: high
Scope-risk: narrow
* test: add unit tests for buildCredentialArnMap and CFN template matching
Bugbash coverage for credential resolution and CFN resource matching:
- buildCredentialArnMap: reads ARN-to-name map from deployed state,
handles multiple credentials, empty/missing state, thrown errors
- findLogicalIdByProperty: gateway by Name property, resourceName
fallback, target by Name, Fn::Join/Fn::Sub intrinsic function
patterns, regex boundary check prevents false substring matches
- findLogicalIdsByType: single gateway fallback, single target
fallback, multiple targets prevent fallback
14 tests, all passing.
Confidence: high
Scope-risk: narrow
* fix: exclude already-deployed logical IDs when building import resource list
When a project already contains an imported resource (gateway + target, agent,
memory, etc.), a subsequent import of a different resource that shares a Name
with the deployed one caused buildResourcesToImport to resolve the OLD
logical ID via findLogicalIdByProperty. The resulting CFN change set then
failed with "Resources [...] passed in ResourceToImport are already in a
stack and cannot be imported."
Thread the deployed template into every buildResourcesToImport callback and
skip logical IDs already present in the stack during both the name lookup
and the single-candidate fallback.
Constraint: GatewayTarget has no structural parent ref in Properties — only the physical-ID tuple (GatewayIdentifier, TargetId), so scoping the synth search by parent gateway is not available.
Rejected: Parse Fn::Ref/Fn::GetAtt from GatewayIdentifier | brittle intrinsic traversal
Rejected: Match by physical TargetId | synth template has no physical ID for new resources
Rejected: Strip deployed resources from synth before lookup | breaks buildImportTemplate
Confidence: high
Scope-risk: narrow
Directive: new callbacks into executeCdkImportPipeline must accept and honor the deployedTemplate arg
Not-tested: multi-region / cross-stack-identifier collisions
* fix(import): translate AccessDenied on GetGateway to a friendly not-found error
When importing a gateway by a well-formed but nonexistent ARN, the
BedrockAgentCore control plane returns AccessDenied (not
ResourceNotFound) for bedrock-agentcore:GetGateway. The CLI surfaced the
raw SDK error — which is misleading when the caller has full Admin
access and the gateway simply doesn't exist.
Catch AccessDenied from getGatewayDetail and return a targeted failure
with guidance: the gateway is likely nonexistent / the ARN is malformed
/ the caller lacks GetGateway. Point the user at list-gateways so they
can confirm.
Constraint: AWS returns AccessDenied instead of ResourceNotFound for
nonexistent gateway IDs; we cannot distinguish the two server-side
Rejected: Client-side ARN existence probe via ListGateways | extra
latency on the happy path and still racy
Confidence: high
Scope-risk: narrow
Directive: Do not swallow other error classes here — only AccessDenied
is reinterpreted
* fix(import): detect AWS_REGION / ARN region mismatch before import
Previously when a user ran import with AWS_REGION=us-west-2 against a
us-east-1 ARN, and no deployment targets existed yet, the CLI silently
synthesized a default target from the ARN's region and proceeded — so
the user would unknowingly import from a different region than they
intended, leaving agentcore.json pointed at the wrong region and
causing cross-region CFN errors on later deploy.
Short-circuit resolveImportTarget when AWS_REGION (or
AWS_DEFAULT_REGION) is set and disagrees with the ARN's region, and
ask the user to reconcile explicitly.
Constraint: Must fail fast before any side effects (writing
aws-targets.json, calling GetGateway)
Rejected: Warn-and-continue | a silent cross-region import is exactly
the failure mode we're preventing
Confidence: high
Scope-risk: narrow
Directive: Only throw when both env region AND ARN region are present —
do not require AWS_REGION to be set
* fix(import): allow re-import of resource after remove without CDK pipeline
After `agentcore remove gateway`, the gateway entry remains in
deployed-state.json (correctly, since CFN still manages it) but is
removed from agentcore.json. A subsequent `agentcore import gateway`
would reject with "already imported" because the dedup check only
looked at deployed-state. Now, when a resource exists in deployed-state
but not in agentcore.json, the import skips the CDK pipeline and just
re-adds the resource to agentcore.json.
Applies to both the gateway-specific and generic import orchestrators.
* style: fix prettier formatting for import-utils and ArnInputScreen
* fix(import): address PR review blockers B4, B6, B7, H2, H5, H7, H8
- B4: Hard-fail when credential provider ARN is not found in deployed
state instead of silently dropping outboundAuth
- B7: Preserve outboundAuth on lambda→lambdaFunctionArn mapping and
allow OAUTH/NONE auth types for lambdaFunctionArn targets
- H2: Remove re-import fast path; run full CDK pipeline so out-of-band
targets are properly imported. Treat noResources as success for
re-imports since all resources are already in the CFN stack
- H5: Replace hardcoded arn:aws: with partition-agnostic arn:[^:]+: in
ARN validation and region extraction regexes
- H7/H8: Add regex validation and max length for executionRoleArn,
use GatewayNameSchema for resourceName, add refine ensuring both
fields are set together or both omitted
* fix(import): remove credential ARN from error messages to resolve CodeQL alert
CodeQL flagged clear-text logging of credential provider ARNs. The
target name provides sufficient context for the user to identify
the issue.1 parent 41c59ef commit 2df1387
24 files changed
Lines changed: 3095 additions & 33 deletions
File tree
- e2e-tests
- fixtures/import
- src
- cli
- aws
- commands/import
- __tests__
- tui/screens/import
- schema/schemas
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
72 | 77 | | |
73 | 78 | | |
74 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
54 | 58 | | |
55 | 59 | | |
56 | 60 | | |
57 | 61 | | |
58 | 62 | | |
59 | 63 | | |
60 | 64 | | |
| 65 | + | |
| 66 | + | |
61 | 67 | | |
62 | 68 | | |
63 | 69 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| |||
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
53 | | - | |
| 54 | + | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| |||
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
| 72 | + | |
71 | 73 | | |
72 | 74 | | |
73 | 75 | | |
| |||
163 | 165 | | |
164 | 166 | | |
165 | 167 | | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
166 | 184 | | |
167 | 185 | | |
168 | 186 | | |
| |||
187 | 205 | | |
188 | 206 | | |
189 | 207 | | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
190 | 275 | | |
191 | 276 | | |
192 | 277 | | |
| |||
0 commit comments