Repository navigation
Description
Problem
A deploy that publishes a version of the input guardrail fails when the guardrail is at Bedrock's quota of versions, and the stack rolls back. The quota is 20 versions per guardrail and cannot be raised (Versions per guardrail in the Amazon Bedrock service quotas). #1079 hit it on a guardrail that had versions 16 to 34 and DRAFT: 19 numbered versions.
Since #1084 the logical ID of the version contains a hash of the guardrail's configuration, so a deploy publishes a version only when the guardrail changed. Two ways to the quota remain:
- The upgrade. The first deploy with fix: guardrail version quota, credentials race, late reconciler writes; CI cleanup #1084 publishes one more version, because the logical ID changes one last time: from the name that
createVersion()of the alpha library gave (InputGuardrailGuardrailVersion…) toInputGuardrailVersion<hash>…. On a stack that earlier deploys brought to the quota, that deploy cannot create the version, and the stack rolls back as in Deploys stop once the input guardrail reaches its version quota #1079. The deployment guide says to count the versions before that deploy, but an operator who has not read the entry finds it only after the rollback. - Over time. Every published version is retained, because a retained version of the orchestrator function can still name it (
publishGuardrailVersionincdk/src/stacks/agent.ts), and nothing deletes a replaced one. Each change of the guardrail adds a version, and so does a deploy that publishes one and then rolls back. A long-lived stack can reach the quota again.
Both points come from the review of #1084 (upgrade, over time). In that review a long-lived stack went from 11 to 12 published versions on its first deploy with the change, and stayed at 12 on the next.
What exists
- The guide entry.
docs/guides/DEPLOYMENT_GUIDE.md:524-572, "Deploys stop once the input guardrail reaches its version quota (Deploys stop once the input guardrail reaches its version quota #1079)", under "Known deployment issues". Line 539 says: "The first deploy with the fix publishes one more version, because the logical ID changes one last time. A guardrail at its quota needs the cleanup below before that deploy." Since fix: guardrail version quota, credentials race, late reconciler writes; CI cleanup #1084 its "Affects" paragraph (line 526) also says to count the guardrail's versions before the first deploy with the fix. The entry then lists the versions (aws bedrock list-guardrails --guardrail-identifier <guardrail-id>), the versions that functions name (aws lambda list-functions --function-version ALL, byGUARDRAIL_IDandGUARDRAIL_VERSION) and the unfinished durable executions, and deletes the other versions (aws bedrock delete-guardrail --guardrail-identifier <guardrail-id> --guardrail-version <n>). - Two preflights on the deploy path.
mise //cdk:deploy(cdk/mise.toml:145-173) runsscripts/preflight-bootstrap.ts, thenscripts/preflight-log-delivery.ts, thencdk deploy, each with the arguments after--.bgagent setupdeploys through that task (cli/src/commands/setup.ts), so it runs them too. A barecdk deployruns neither.preflight-bootstrap.tsis read-only (aws cloudformation describe-stacks). It reports PASS, WARN or FAIL (cdk/src/bootstrap/preflight.ts), prints the verdict as JSON with--json, exits 1 on FAIL and is skipped withABCA_SKIP_BOOTSTRAP_PREFLIGHT=1.mise //cdk:preflightruns it alone.preflight-log-delivery.tsreads the resources of the stack that is being deployed (aws cloudformation list-stack-resources). It takes the stack name from--stack-name,-c stackName=,STACK_NAME,cdk.context.jsonorcdk.json, elsebackgroundagent-dev(resolveStackName), forwards--profileand--region, and treats a stack that does not exist as a fresh install. Its tests (cdk/test/scripts/preflight-log-delivery.test.ts) run the script with a stand-inawsonPATH.
- The resources. The guardrail is the
AWS::Bedrock::Guardrailof the root stack whose logical ID starts withInputGuardrail. Its name istask-input-guardrail-<stack name>, cut off after 50 characters. The stack has oneAWS::Bedrock::GuardrailVersion. - The API.
ListGuardrailswithguardrailIdentifier(an ID or an ARN) lists every version of one guardrail, in pages (API reference). The reference does not say whether that listing holdsDRAFT; Deploys stop once the input guardrail reaches its version quota #1079 reports its guardrail with versions 16 to 34 andDRAFT. The IAM action isbedrock:ListGuardrails. The CloudFormation execution role already has it (BedrockGuardrailsAndLoggingincdk/src/bootstrap/policies/observability.ts), but a preflight runs with the operator's own credentials, as the two above do.
Proposal
A third preflight, read-only: cdk/scripts/preflight-guardrail-versions.ts, run by mise //cdk:deploy before cdk deploy, and on its own as mise //cdk:preflight:guardrail-versions.
- Resolve the stack, the profile and the Region as
preflight-log-delivery.tsdoes. Share that code instead of copying it a third time. - Read the stack's resources. No stack: nothing to check. Otherwise take the physical ID of the guardrail and the logical IDs of its version resources.
- List the guardrail's versions and count the numbered ones.
- Report:
- FAIL, before
cdk deploybuilds or uploads an asset, when the guardrail is at its quota and the stack's version does not have the hash name yet (InputGuardrailVersion, 16 hexadecimal digits, and the 8 characters that CDK appends). That deploy is certain to publish a version. The message gives the count, says that the deploy would fail and roll back, and names the guide entry. - WARN when the guardrail is at its quota and the version already has the hash name (the next change of the guardrail cannot be published), and when the count is close to the quota, for example within five.
- PASS otherwise, with the count in the line, so that every deploy log shows it.
- FAIL, before
ABCA_SKIP_GUARDRAIL_PREFLIGHT=1skips it.--jsonprints the verdict, as in the bootstrap preflight.
To decide when implementing:
- What happens when the versions cannot be read (no AWS CLI, or no
bedrock:ListGuardrailsfor the operator). The two existing preflights stop the deploy. This one guards against a rollback, not against a loss, so a warning that names the missing permission may be enough. - Whether the quota counts
DRAFT. The one observation (Deploys stop once the input guardrail reaches its version quota #1079) is a refusal at 19 numbered versions. - Whether
bgagent setupmakes the check exact. It runscdk diffbefore it deploys, and the diff shows whether a version would be created.
Not proposed: deleting unused versions automatically. Whether a version is unused depends on the unfinished durable executions of every retained version of the orchestrator function (see the guide entry).
Acceptance criteria
- With a stand-in
aws, as inpreflight-log-delivery.test.ts:- no stack: exit 0, and Bedrock is not called;
- a version resource without the hash name and a guardrail at its quota: exit 1, and the message has the count and names the guide entry;
- the same version resource and a count close to the quota: exit 0 with a warning;
- a version with the hash name and a guardrail at its quota: exit 0 with a warning;
- a count below the warning threshold: exit 0, and the line has the count;
- a listing that comes in two pages is counted whole;
--profile,--regionand the stack name reach both calls;ABCA_SKIP_GUARDRAIL_PREFLIGHT=1: exit 0 without a call.
- The stand-in records every call, and the script makes none that changes anything.
mise //cdk:deployruns the preflight beforecdk deploy, and a FAIL stops the task.bgagent setupshows the FAIL line.- The guide entry,
cdk/scripts/README.mdand the command list ofcdk/AGENTS.mddescribe the preflight and name the permission it needs. - One run against a deployed stack confirms what was only read so far: that the physical ID of the guardrail resource is accepted as
--guardrail-identifier(the L1 inaws-cdk-libreadsRefof this type as the ARN, and the CloudFormation reference leaves thatRefundescribed), whether the listing of one guardrail holdsDRAFT, and the count at which Bedrock refuses the next version.
Activity