Skip to content

fix(cdk): resolveBedrockModelIds rejects the documented -c string override #628

Description

@AshrafBen10

Summary

resolveBedrockModelIds (cdk/src/constructs/bedrock-models.ts) rejects any context value that isn't a real array. But CDK delivers a -c key=value context value as a raw string, not parsed JSON — so the -c form the function's own JSDoc advertises throws at synth:

cdk deploy -c 'bedrockModels=["anthropic.claude-sonnet-4-6"]'
# Error: Context 'bedrockModels' must be a non-empty array of foundation-model IDs …;
#        got "[\"anthropic.claude-sonnet-4-6\"]".

The cdk.context.json array form works; the documented -c CLI form does not.

Context

Flagged by @isadeks in the re-review of #358 as a non-blocking follow-up: the AZ override (resolveAgentCoreAzOverride) was fixed there to JSON.parse a string context value; resolveBedrockModelIds shares the same structural limitation and its JSDoc already documents a -c bedrockModels='[...]' form.

Acceptance criteria

  • resolveBedrockModelIds JSON.parses a string context value before the array check, so the -c form and the cdk.context.json array form behave identically.
  • A non-JSON / malformed string (a true typo) still fails with the existing clear, key-named error (loud-fail preserved).
  • All existing validation still fires (non-array, empty array, non-string/empty entry, region-prefixed us./eu./apac. inference-profile ID).
  • Unit tests cover: -c JSON-string array (success), and a JSON string that doesn't parse to an array (throws).
  • No new dependencies; tsc, ESLint, and the AI004 masking scan stay clean.

Out of scope

No behavior change to the default model set or the grant sites; this only fixes context-value parsing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions