Repository navigation
feat(core): check CDK bootstrap before deploy and sandbox - #999
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: 13e9380 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
VarshithaPamisetty
previously approved these changes
Oct 23, 2026
VarshithaPamisetty
approved these changes
Oct 23, 2026
This branch had an error being deployed
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.
Problem
In an account and Region that were never CDK-bootstrapped,
npm run deployandnpm run sandboxfail only after synthesis and the asset builds, with:The preflight checks credentials but not bootstrap. The CDK error does not name the account or Region, and a plain
npx cdk bootstrap aws://<account>/<region>run in a Blocks project synthesizes the whole app first, because CDK synthesizes whenevercdk.jsonhas anapp, even with an explicit environment (CdkToolkit.defineEnvironments).Issue #, if available:
Changes
preflight-bootstrap.ts, wired throughassertAwsCredentials({ checkBootstrap: true })fromdeploy()andstartSandbox()). After STS verifies the credentials, it reads/cdk-bootstrap/<qualifier>/versionwith those same credentials, in the deploy Region, in parallel with the existing account-metadata reads (one attempt, 1 s connect / 2 s request timeout).ParameterNotFoundstops the deploy. The deployment target is printed first, then the command stops with:--app=stopscdk bootstrapfrom synthesizing the app. From the project directory, CDK still reads thecdk.jsonprofile and qualifier. A denied read, a network error, a timeout or any other error is inconclusive and the deploy continues. CDK reads this parameter through its bootstrap roles, so credentials that cannot read it may still deploy.resolveDeploymentTargetnow also returns@aws-cdk/core:bootstrapQualifier, fromcdk.jsoncontext, thencdk.context.json, then~/.cdk.jsoncontext. That is the CLI's lookup order (Configuration.loadConfigFiles). A malformedcdk.context.jsonis ignored here; CDK reports it itself. A qualifier that the bootstrap template rejects skips the check.Account, used for the command.npm run deploy. The appAGENTS.mdtells coding agents to ask the user before running it.AGENTS.md. Changeset forcore,blocksandcreate-blocks-app.Known limit: an app that sets a custom qualifier only in code (
synthesizer: new DefaultStackSynthesizer({ qualifier })) and not in context would be checked against the default qualifier. The message says to set the same value as@aws-cdk/core:bootstrapQualifierincdk.json, which the synthesizer also reads.Validation
preflight-bootstrap.test.ts:deployandsandboxstop with the command, after printing the target.cdk.json.Error: the deploy continues.<region>.deployment-target.test.tscases: qualifier precedence, and malformedcdk.context.json.npm run build,npm run lint,npm run lint:deps: pass. Rootnpm test(all workspaces): exit 0, no failures;corealone is 1611 pass, 0 fail.npm run test:e2e:local: 0 failures.deploy()path: a temp project, withAWS_ENDPOINT_URLpointed at a local fake STS/SSM endpoint. The real SDK clients and error mapping were used, with no AWS account.ssm@eu-south-2, and thecdk.jsonapp (a marker script) never ran.AccessDeniedException: passes the preflight and continues to client codegen.--app=behavior (aws-cdk 2.1138.0):cdk bootstrap aws://…in a directory whosecdk.jsonhas anappran the app. With--app=, the app did not run, and the CLI went straight toBootstrapping environment aws://….deploy()andstartSandbox()with an AWS profile, from a throwaway project with no backend):sa-east-1(not bootstrapped, confirmed withaws ssm get-parameter):deployandsandboxeach exited 1 in about 2 s with the message above. The account and Region in the printed command were correct, the app incdk.jsonnever ran, and no CloudFormation call was made.us-east-1(bootstrapped, version 32): passed the check and continued to client codegen, then failed because the throwaway project has no backend. CDK never ran.cdk bootstrapcommand.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.