fix(cli): The bootstrap stack is environment-wide and build-type-ag... (#1377)#40
Draft
aidandaly24 wants to merge 1 commit into
Draft
fix(cli): The bootstrap stack is environment-wide and build-type-ag... (#1377)#40aidandaly24 wants to merge 1 commit into
aidandaly24 wants to merge 1 commit into
Conversation
…rror (aws#1377) Catch ecr:CreateRepository AccessDenied during CDK bootstrap and remap it to a dedicated BootstrapEcrAccessDeniedError that explains ECR is needed only by the shared CDK bootstrap stack (not by CodeZip agents) and gives a concrete workaround. The vended ECR-less bootstrap template and --no-container-assets opt-in flag are intentionally NOT touched — design-gated and out of scope. Refs aws#1377
Coverage Report
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs aws#1377
Issues
agentcore deployin an AWS account whose SCP/IAM deniesecr:CreateRepositoryis hard-blocked: the deploy auto-bootstraps the shared CDKToolkit stack, which unconditionally tries to create an ECR repository, so bootstrap (and therefore the whole deploy) fails with "ECR Permission Denied - ecr:CreateRepository" even though CodeZip never uses ECR. Only workaround is deploying in a less-restricted account.Root cause
Verified: CLI bootstrap (wrapper.ts:317) passes no BootstrapSource, so toolkit-lib deploys the modern bootstrap template whose ContainerAssetsRepository (ECR) at bootstrap-template.yaml:256 is unconditional; CodeZip needs no ECR (AgentCoreRuntime/AgentEnvironment gate ECR on build==='Container' only, confirmed at pinned alpha.19). The ECR demand is purely a shared-bootstrap-stack artifact, blocked by SCPs denying ecr:CreateRepository.
The fix
The bootstrap stack is environment-wide and build-type-agnostic by design, so the clean fix is to let the CLI bootstrap with a customized template that omits (or makes conditional) ContainerAssetsRepository when ECR is unavailable/unneeded. toolkit-lib already supports this: BootstrapOptions.source accepts { source: 'custom', templateFile } (verified in node_modules/@aws-cdk/toolkit-lib/lib/api/bootstrap/bootstrap-props.d.ts and bootstrap-environment.d.ts; there is NO --no-container-assets option in toolkit-lib, so a custom template is the only lever). Concretely: (1) vend a slimmed bootstrap template (clone of the modern template minus ContainerAssetsRepository and its ECR IAM grants) and pass it via the bootstrap source through CdkToolkitWrapper.bootstrap (wrapper.ts:317); gate its use on a flag like
--no-container-assetsor auto-detect (no Container agents in the project). Design decision required: an ECR-less bootstrap breaks any later Container build in that same environment, so it must be opt-in or clearly re-bootstrap-on-demand. Cheaper interim fix: detect the ecr:CreateRepository AccessDenied during bootstrap and emit an actionable error explaining ECR is needed only by the shared CDK bootstrap stack (not by CodeZip itself), with the slim-template/flag workaround. The unconditional ECR resource itself lives upstream in the aws-cdk modern bootstrap template, which the CLI can only override via a custom template, not patch. Dependency-range note: src/assets/cdk/package.json pins^0.1.0-alpha.19, which floats to later 0.1.0-alpha tags at install, but ECR-on-Container-only behavior is unchanged through alpha.39 — no version bump fixes this.Files touched: agentcore-cli: src/cli/cdk/toolkit-lib/wrapper.ts (bootstrap() ~L317-324, add a custom BootstrapSource via options.source), src/cli/operations/deploy/preflight.ts (bootstrapEnvironment L329-335), src/cli/commands/deploy/actions.ts (auto-bootstrap branch L407-421); plus a vended ECR-less bootstrap template asset. The unconditional ECR resource lives upstream in the aws-cdk modern bootstrap template (node_modules/@aws-cdk/toolkit-lib/lib/api/bootstrap/bootstrap-template.yaml:256, ContainerAssetsRepository), overridable only via a custom template.
Validation evidence
The fix was verified by reproducing the original symptom and re-running after the change:
Test suite: green.
Staged on the fork as a draft for human review. Promote to aws/agentcore-cli after vetting.