@composurecdk/bedrock 0.11.1 → 0.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +41 -21
  2. package/dist/commonjs/arn.d.ts +12 -0
  3. package/dist/commonjs/arn.d.ts.map +1 -0
  4. package/dist/commonjs/arn.js +27 -0
  5. package/dist/commonjs/arn.js.map +1 -0
  6. package/dist/commonjs/grants.d.ts +27 -9
  7. package/dist/commonjs/grants.d.ts.map +1 -1
  8. package/dist/commonjs/grants.js +68 -30
  9. package/dist/commonjs/grants.js.map +1 -1
  10. package/dist/commonjs/index.d.ts +1 -1
  11. package/dist/commonjs/index.d.ts.map +1 -1
  12. package/dist/commonjs/index.js +2 -1
  13. package/dist/commonjs/index.js.map +1 -1
  14. package/dist/commonjs/inference-profile.d.ts +25 -9
  15. package/dist/commonjs/inference-profile.d.ts.map +1 -1
  16. package/dist/commonjs/inference-profile.js +41 -25
  17. package/dist/commonjs/inference-profile.js.map +1 -1
  18. package/dist/commonjs/inference-target.d.ts +42 -4
  19. package/dist/commonjs/inference-target.d.ts.map +1 -1
  20. package/dist/commonjs/inference-target.js +72 -25
  21. package/dist/commonjs/inference-target.js.map +1 -1
  22. package/dist/esm/arn.d.ts +12 -0
  23. package/dist/esm/arn.d.ts.map +1 -0
  24. package/dist/esm/arn.js +23 -0
  25. package/dist/esm/arn.js.map +1 -0
  26. package/dist/esm/grants.d.ts +27 -9
  27. package/dist/esm/grants.d.ts.map +1 -1
  28. package/dist/esm/grants.js +69 -31
  29. package/dist/esm/grants.js.map +1 -1
  30. package/dist/esm/index.d.ts +1 -1
  31. package/dist/esm/index.d.ts.map +1 -1
  32. package/dist/esm/index.js +1 -1
  33. package/dist/esm/index.js.map +1 -1
  34. package/dist/esm/inference-profile.d.ts +25 -9
  35. package/dist/esm/inference-profile.d.ts.map +1 -1
  36. package/dist/esm/inference-profile.js +39 -25
  37. package/dist/esm/inference-profile.js.map +1 -1
  38. package/dist/esm/inference-target.d.ts +42 -4
  39. package/dist/esm/inference-target.d.ts.map +1 -1
  40. package/dist/esm/inference-target.js +66 -20
  41. package/dist/esm/inference-target.js.map +1 -1
  42. package/package.json +2 -2
package/README.md CHANGED
@@ -13,14 +13,6 @@ import { createModelAlarmBuilder, inferenceProfile, modelGrants } from "@composu
13
13
  const haiku = inferenceProfile.geographic({
14
14
  model: FoundationModelIdentifier.ANTHROPIC_CLAUDE_HAIKU_4_5_20251001_V1_0,
15
15
  geography: "eu",
16
- routingRegions: [
17
- "eu-central-1",
18
- "eu-north-1",
19
- "eu-south-1",
20
- "eu-south-2",
21
- "eu-west-1",
22
- "eu-west-3",
23
- ],
24
16
  });
25
17
 
26
18
  compose(
@@ -49,36 +41,57 @@ compose(
49
41
 
50
42
  A profile's id is derived from its model, so the id a caller invokes and the model it is granted cannot drift apart. Use `new FoundationModelIdentifier("…")` for a model newer than the installed CDK's constants.
51
43
 
52
- `routingRegions` are the Regions a geographic profile routes to from your source Region. They vary by source Region and are not derivable from the geography, so they are supplied rather than guessed: take them from the model's page in the Bedrock user guide or from `aws bedrock get-inference-profile`. The source Region is always included.
44
+ ### Routing Regions
53
45
 
54
- For an id that arrives as a string, such as from an environment variable:
46
+ A geographic profile is owned by AWS. AWS chooses the Regions it routes to, which differ by source Region and grow over time without notice. You choose the profile, not its destinations.
47
+
48
+ By default the grant therefore covers the foundation model in every Region, conditioned on `bedrock:InferenceProfileArn` so it is reachable only through that profile. The profile keeps requests inside its geography, so naming the destinations would not narrow where they run. A copy of the list would break the profile when AWS adds a Region. Bedrock checks the model in every Region the profile may route to before it routes a request, so one missing Region denies every call, not only those routed there.
49
+
50
+ Pass `routingRegions` when the policy must name each Region: for a service control policy, or a policy scanner that flags a wildcard in any ARN. Take them from `aws bedrock get-inference-profile`, and re-check them when AWS changes the profile. The source Region is always included.
55
51
 
56
52
  ```ts
57
- const profile = inferenceProfile.parse(
58
- "eu.anthropic.claude-haiku-4-5-20251001-v1:0",
59
- routingRegions,
60
- );
61
- foundationModelFor(profile.profileId).modelId; // "anthropic.claude-haiku-4-5-20251001-v1:0"
53
+ inferenceProfile.geographic({
54
+ model,
55
+ geography: "eu",
56
+ routingRegions: ["eu-central-1", "eu-west-3"],
57
+ });
62
58
  ```
63
59
 
64
- `parse` and `foundationModelFor` throw on an id without a known geography or `global` prefix (`INFERENCE_PROFILE_GEOGRAPHIES`), rather than mistake a provider such as `anthropic.` for one.
60
+ The default is not the shape in the Bedrock user guide's example, which lists each Region. It is the same statement with the Region left open, verified against live IAM ([#628](https://github.com/laazyj/composureCDK/issues/628)).
61
+
62
+ ### Ids that arrive as strings
63
+
64
+ `inferenceTarget.fromId` resolves an id read from configuration or an environment variable:
65
+
66
+ | Id | Target |
67
+ | ----------------------------------- | ------------------------ |
68
+ | `anthropic.claude-…` | A foundation model |
69
+ | `eu.anthropic.claude-…`, `global.…` | A system-defined profile |
70
+ | `arn:…:provisioned-model/…` | A provisioned model |
71
+
72
+ ```ts
73
+ const ids = ["anthropic.claude-sonnet-5-5", "us.anthropic.claude-haiku-4-5-20251001-v1:0"];
74
+ createFunctionBuilder().grant(...ids.map((id) => modelGrants.invoke(inferenceTarget.fromId(id))));
75
+ ```
76
+
77
+ It throws on a two-part id with an unknown prefix (`INFERENCE_PROFILE_GEOGRAPHIES`) rather than grant it as a model named after a geography. It also throws on an inference profile ARN, because the model the profile routes to cannot be read from it. `inferenceProfile.parse` and `foundationModelFor` accept only profile ids.
65
78
 
66
79
  Profiles are plain values rather than the alpha `CrossRegionInferenceProfile` L2, for the [reasons given for guardrails](#why-the-l1-constructs-not-the-alpha-l2) and because its grants don't match what live IAM needs ([#536](https://github.com/laazyj/composureCDK/issues/536)).
67
80
 
68
81
  ## Grants
69
82
 
70
- `modelGrants.invoke(target)` grants `bedrock:InvokeModel` and `bedrock:InvokeModelWithResponseStream`, which together cover `InvokeModel`, `Converse` and their streaming variants. Pass it to any grantee builder's `grant(...)`.
83
+ `modelGrants.invoke(target)` grants `bedrock:InvokeModel` and `bedrock:InvokeModelWithResponseStream`, which together cover `InvokeModel`, `Converse` and their streaming variants. A caller that never streams can pass `{ streaming: false }` for `bedrock:InvokeModel` alone. Pass the grant to any grantee builder's `grant(...)`.
71
84
 
72
85
  | Target | Statements |
73
86
  | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
74
87
  | Model | The foundation model in the source Region |
75
- | Geographic | The profile; the foundation model in the source Region and every routing Region, conditioned on `bedrock:InferenceProfileArn` |
88
+ | Geographic | The profile; the foundation model in every Region, or in the source Region and each listed routing Region, conditioned on `bedrock:InferenceProfileArn` |
76
89
  | Global | The profile; the foundation model in the source Region; the Region-less foundation model ARN with `aws:RequestedRegion: unspecified`. Both model statements are conditioned on `bedrock:InferenceProfileArn` |
77
90
  | Application | The profile; its source's foundation models, conditioned on `bedrock:InferenceProfileArn` being the application profile |
78
91
 
79
92
  The model and system-profile rows follow the policies in the Bedrock user guide for [geographic](https://docs.aws.amazon.com/bedrock/latest/userguide/geographic-cross-region-inference.html#geographic-cris-iam-setup) and [global](https://docs.aws.amazon.com/bedrock/latest/userguide/global-cross-region-inference.html#global-cris-iam-setup) cross-Region inference. The `bedrock:InferenceProfileArn` condition makes the foundation models reachable only through the profile ([GENSEC01-BP01](https://docs.aws.amazon.com/wellarchitected/latest/generative-ai-lens/gensec01-bp01.html)); to also call a model directly, grant it separately. The application row was verified against live IAM for a global source: the source profile needs no statement of its own.
80
93
 
81
- `invocationArns(target, scope)` returns the same resource ARNs for policies you write yourself, such as service control policies.
94
+ `invocationArns(target, scope)` returns the same resource ARNs for policies you write yourself, such as service control policies. For a geographic profile without `routingRegions` that is one Region-wildcard model ARN, so list the Regions when the policy needs them.
82
95
 
83
96
  ## Alarms
84
97
 
@@ -95,7 +108,7 @@ AWS publishes no recommended alarm thresholds for Bedrock. The [Generative AI Le
95
108
  | `timeToFirstToken` | `TimeToFirstToken` (p90) | opt-in, threshold required |
96
109
  | `estimatedTpmQuotaUsage` | `EstimatedTPMQuotaUsage` (Max) | opt-in, `quota` required; 80% of quota |
97
110
 
98
- `invocationClientErrors` includes `AccessDenied`, so it catches an under-granted routing Region, which fails only for requests routed there. Missing data is not breaching. Defaults are exported as `MODEL_ALARM_DEFAULTS`.
111
+ `invocationClientErrors` includes `AccessDenied`, so it catches a stale `routingRegions` list, which denies every call through the profile. Missing data is not breaching. Defaults are exported as `MODEL_ALARM_DEFAULTS`.
99
112
 
100
113
  ```ts
101
114
  createModelAlarmBuilder()
@@ -157,7 +170,14 @@ compose(
157
170
 
158
171
  By default the guardrail filters every harmful-content category (sexual, violence, hate, insults, misconduct) and prompt attacks at `HIGH`, with the Bedrock console's default blocked message (`GUARDRAIL_DEFAULTS`). Topic, word, sensitive-information and contextual-grounding policies depend on the workload and are not defaulted.
159
172
 
160
- `requireGuardrail` makes the grantee [use the guardrail](https://docs.aws.amazon.com/bedrock/latest/userguide/guardrails-permissions-id.html): the invoke allow is conditioned on `bedrock:GuardrailIdentifier`, an explicit deny refuses any other call, and the grantee may apply the guardrail. `guardrailGrants.apply` grants `bedrock:ApplyGuardrail` alone.
173
+ `requireGuardrail` makes the grantee [use the guardrail](https://docs.aws.amazon.com/bedrock/latest/userguide/guardrails-permissions-id.html): the invoke allow is conditioned on `bedrock:GuardrailIdentifier`, an explicit deny refuses any other call, and the grantee may apply the guardrail. `guardrailGrants.apply` grants `bedrock:ApplyGuardrail` alone, and accepts a guardrail the app did not build as `{ guardrailArn, version }`.
174
+
175
+ For a guardrail chosen at run time, such as one named in configuration:
176
+
177
+ - `requireGuardrail: "any"` requires every call to carry some guardrail in the grantee's account and Region, and lets the grantee apply any of them.
178
+ - `guardrailGrants.applyAny()` lets the grantee apply any guardrail in its account and Region, without requiring one. Use it where a call may or may not name a guardrail.
179
+
180
+ Prefer a reference where the guardrail is known at synth.
161
181
 
162
182
  Guardrail errors and throttles are only published per account, so the guardrail's alarms are opt-in: `invocationsIntervened` (Sum) and `invocationLatency` (p90), each with a threshold you supply.
163
183
 
@@ -0,0 +1,12 @@
1
+ import { Stack } from "aws-cdk-lib";
2
+ import type { IConstruct } from "constructs";
3
+ type Environment = Pick<Stack, "partition" | "region" | "account">;
4
+ /**
5
+ * The partition, Region and account of `scope`'s stack, or the `AWS::`
6
+ * pseudo-parameters without a scope. @internal
7
+ */
8
+ export declare function environmentOf(scope: IConstruct | undefined): Environment;
9
+ /** A `bedrock` ARN with a slash-separated resource name. @internal */
10
+ export declare function bedrockArn(partition: string, resource: string, resourceName: string, region: string, account?: string): string;
11
+ export {};
12
+ //# sourceMappingURL=arn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arn.d.ts","sourceRoot":"","sources":["../../src/arn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,KAAK,WAAW,GAAG,IAAI,CAAC,KAAK,EAAE,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC,CAAC;AAEnE;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,WAAW,CAIxE;AAED,sEAAsE;AACtE,wBAAgB,UAAU,CACxB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,EACd,OAAO,SAAK,GACX,MAAM,CAUR"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.environmentOf = environmentOf;
4
+ exports.bedrockArn = bedrockArn;
5
+ const aws_cdk_lib_1 = require("aws-cdk-lib");
6
+ /**
7
+ * The partition, Region and account of `scope`'s stack, or the `AWS::`
8
+ * pseudo-parameters without a scope. @internal
9
+ */
10
+ function environmentOf(scope) {
11
+ return scope === undefined
12
+ ? { partition: aws_cdk_lib_1.Aws.PARTITION, region: aws_cdk_lib_1.Aws.REGION, account: aws_cdk_lib_1.Aws.ACCOUNT_ID }
13
+ : aws_cdk_lib_1.Stack.of(scope);
14
+ }
15
+ /** A `bedrock` ARN with a slash-separated resource name. @internal */
16
+ function bedrockArn(partition, resource, resourceName, region, account = "") {
17
+ return aws_cdk_lib_1.Arn.format({
18
+ partition,
19
+ service: "bedrock",
20
+ region,
21
+ account,
22
+ resource,
23
+ resourceName,
24
+ arnFormat: aws_cdk_lib_1.ArnFormat.SLASH_RESOURCE_NAME,
25
+ });
26
+ }
27
+ //# sourceMappingURL=arn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arn.js","sourceRoot":"","sources":["../../src/arn.ts"],"names":[],"mappings":";;AASA,sCAIC;AAGD,gCAgBC;AAhCD,6CAAyD;AAKzD;;;GAGG;AACH,SAAgB,aAAa,CAAC,KAA6B;IACzD,OAAO,KAAK,KAAK,SAAS;QACxB,CAAC,CAAC,EAAE,SAAS,EAAE,iBAAG,CAAC,SAAS,EAAE,MAAM,EAAE,iBAAG,CAAC,MAAM,EAAE,OAAO,EAAE,iBAAG,CAAC,UAAU,EAAE;QAC3E,CAAC,CAAC,mBAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;AACtB,CAAC;AAED,sEAAsE;AACtE,SAAgB,UAAU,CACxB,SAAiB,EACjB,QAAgB,EAChB,YAAoB,EACpB,MAAc,EACd,OAAO,GAAG,EAAE;IAEZ,OAAO,iBAAG,CAAC,MAAM,CAAC;QAChB,SAAS;QACT,OAAO,EAAE,SAAS;QAClB,MAAM;QACN,OAAO;QACP,QAAQ;QACR,YAAY;QACZ,SAAS,EAAE,uBAAS,CAAC,mBAAmB;KACzC,CAAC,CAAC;AACL,CAAC"}
@@ -5,13 +5,25 @@ import { type InferenceTarget } from "./inference-target.js";
5
5
  /** Options for {@link modelGrants.invoke}. */
6
6
  export interface ModelInvokeGrantOptions {
7
7
  /**
8
- * Requires every invocation to apply this guardrail version. The allow is
9
- * conditioned on `bedrock:GuardrailIdentifier`, an explicit deny refuses
10
- * calls without it, and the grantee may apply the guardrail.
8
+ * Requires every invocation to apply a guardrail. The allow is conditioned
9
+ * on `bedrock:GuardrailIdentifier`, an explicit deny refuses calls without
10
+ * it, and the grantee may apply the guardrail.
11
+ *
12
+ * A reference requires that guardrail version. `"any"` requires some
13
+ * guardrail in the grantee's account and Region, for a workload that picks
14
+ * its guardrail at run time; prefer a reference where the guardrail is
15
+ * known at synth.
11
16
  *
12
17
  * @see https://docs.aws.amazon.com/bedrock/latest/userguide/guardrails-permissions-id.html
13
18
  */
14
- requireGuardrail?: Resolvable<GuardrailReference>;
19
+ requireGuardrail?: Resolvable<GuardrailReference | "any">;
20
+ /**
21
+ * Whether to grant `bedrock:InvokeModelWithResponseStream` alongside
22
+ * `bedrock:InvokeModel`. Set `false` for a caller that never streams.
23
+ *
24
+ * @default true
25
+ */
26
+ streaming?: boolean;
15
27
  }
16
28
  /**
17
29
  * Consumer-side grant helpers for invoking Amazon Bedrock models. Pass one to
@@ -27,14 +39,14 @@ export declare const modelGrants: {
27
39
  * Invoke the target through `InvokeModel`, `Converse` or their streaming
28
40
  * variants.
29
41
  *
30
- * For a cross-Region profile this also grants the foundation model in the
31
- * source Region and every Region the profile routes to, conditioned on
32
- * `bedrock:InferenceProfileArn` so those models are reachable only through
33
- * the profile.
42
+ * For a cross-Region profile this also grants the foundation model, in
43
+ * every Region or in the profile's listed `routingRegions`, conditioned on
44
+ * `bedrock:InferenceProfileArn` so the model is reachable only through the
45
+ * profile.
34
46
  *
35
47
  * @see https://docs.aws.amazon.com/wellarchitected/latest/generative-ai-lens/gensec01-bp01.html
36
48
  */
37
- invoke: (target: Resolvable<InferenceTarget>, { requireGuardrail }?: ModelInvokeGrantOptions) => Grant<IGrantable>;
49
+ invoke: (target: Resolvable<InferenceTarget>, { requireGuardrail, streaming }?: ModelInvokeGrantOptions) => Grant<IGrantable>;
38
50
  };
39
51
  /**
40
52
  * Consumer-side grant helpers for Amazon Bedrock guardrails.
@@ -47,5 +59,11 @@ export declare const guardrailGrants: {
47
59
  * `ApplyGuardrail` API or a model invocation that names it.
48
60
  */
49
61
  apply: (guardrail: Resolvable<GuardrailReference>) => Grant<IGrantable>;
62
+ /**
63
+ * Apply any guardrail in the grantee's account and Region, for a caller
64
+ * that may name one at run time. Where the guardrail is known, `apply` it;
65
+ * where every call must carry one, `modelGrants.invoke(…, { requireGuardrail })`.
66
+ */
67
+ applyAny: () => Grant<IGrantable>;
50
68
  };
51
69
  //# sourceMappingURL=grants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"grants.d.ts","sourceRoot":"","sources":["../../src/grants.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,UAAU,EAAmB,MAAM,qBAAqB,CAAC;AAClG,OAAO,EAAW,KAAK,KAAK,EAAY,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACpF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,KAAK,eAAe,EAAiC,MAAM,uBAAuB,CAAC;AAU5F,8CAA8C;AAC9C,MAAM,WAAW,uBAAuB;IACtC;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,UAAU,CAAC,kBAAkB,CAAC,CAAC;CACnD;AAmDD;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW;IACtB;;;;;;;;;;OAUG;qBAEO,UAAU,CAAC,eAAe,CAAC,yBACb,uBAAuB,KAC5C,KAAK,CAAC,UAAU,CAAC;CAOrB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,eAAe;IAC1B;;;OAGG;uBACgB,UAAU,CAAC,kBAAkB,CAAC,KAAG,KAAK,CAAC,UAAU,CAAC;CAItE,CAAC"}
1
+ {"version":3,"file":"grants.d.ts","sourceRoot":"","sources":["../../src/grants.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,UAAU,EAAmB,MAAM,qBAAqB,CAAC;AAElG,OAAO,EAAW,KAAK,KAAK,EAAY,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACpF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,EACL,KAAK,eAAe,EAIrB,MAAM,uBAAuB,CAAC;AAY/B,8CAA8C;AAC9C,MAAM,WAAW,uBAAuB;IACtC;;;;;;;;;;;OAWG;IACH,gBAAgB,CAAC,EAAE,UAAU,CAAC,kBAAkB,GAAG,KAAK,CAAC,CAAC;IAC1D;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AA8FD;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW;IACtB;;;;;;;;;;OAUG;qBAEO,UAAU,CAAC,eAAe,CAAC,oCACK,uBAAuB,KAC9D,KAAK,CAAC,UAAU,CAAC;CAOrB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,eAAe;IAC1B;;;OAGG;uBACgB,UAAU,CAAC,kBAAkB,CAAC,KAAG,KAAK,CAAC,UAAU,CAAC;IAIrE;;;;OAIG;oBAGW,KAAK,CAAC,UAAU,CAAC;CAKhC,CAAC"}
@@ -3,52 +3,78 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.guardrailGrants = exports.modelGrants = void 0;
4
4
  const aws_iam_1 = require("aws-cdk-lib/aws-iam");
5
5
  const core_1 = require("@composurecdk/core");
6
+ const arn_js_1 = require("./arn.js");
6
7
  const inference_target_js_1 = require("./inference-target.js");
8
+ const INVOKE_ACTION = "bedrock:InvokeModel";
7
9
  /**
8
10
  * Streaming operations (`InvokeModelWithResponseStream`, `ConverseStream`)
9
11
  * require both actions.
10
12
  *
11
13
  * @see https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonbedrock.html
12
14
  */
13
- const INVOKE_ACTIONS = ["bedrock:InvokeModel", "bedrock:InvokeModelWithResponseStream"];
14
- /** The versioned identifier `bedrock:GuardrailIdentifier` carries. */
15
- function identifierOf(guardrail) {
16
- return `${guardrail.guardrailArn}:${guardrail.version}`;
15
+ const INVOKE_ACTIONS = [INVOKE_ACTION, "bedrock:InvokeModelWithResponseStream"];
16
+ /**
17
+ * Every guardrail in `scope`'s account and Region. The versioned identifiers
18
+ * `bedrock:GuardrailIdentifier` carries (`…:guardrail/<id>:<version>`) match
19
+ * it as a `StringLike` pattern.
20
+ */
21
+ function anyGuardrailArn(scope) {
22
+ const { partition, region, account } = (0, arn_js_1.environmentOf)(scope);
23
+ return (0, arn_js_1.bedrockArn)(partition, "guardrail", "*", region, account);
24
+ }
25
+ function requirementOf(guardrail, scope) {
26
+ if (guardrail === "any") {
27
+ const arn = anyGuardrailArn(scope);
28
+ return { like: true, identifier: arn, applyArn: arn };
29
+ }
30
+ return {
31
+ like: false,
32
+ identifier: `${guardrail.guardrailArn}:${guardrail.version}`,
33
+ applyArn: guardrail.guardrailArn,
34
+ };
17
35
  }
18
- function grantInvoke(target, grantee, guardrail) {
19
- const statements = (0, inference_target_js_1.invocationStatements)(target, (0, inference_target_js_1.scopeOf)(grantee.grantPrincipal));
20
- const identifier = guardrail && identifierOf(guardrail);
36
+ function withGuardrail(conditions, required) {
37
+ const match = required.like ? "StringLike" : "StringEquals";
38
+ return {
39
+ ...conditions,
40
+ [match]: {
41
+ ...conditions?.[match],
42
+ "bedrock:GuardrailIdentifier": required.identifier,
43
+ },
44
+ };
45
+ }
46
+ function grantInvoke(target, grantee, guardrail, streaming) {
47
+ const scope = (0, inference_target_js_1.scopeOf)(grantee.grantPrincipal);
48
+ const actions = streaming ? INVOKE_ACTIONS : [INVOKE_ACTION];
49
+ const statements = (0, inference_target_js_1.invocationStatements)(target, scope);
50
+ const required = guardrail && requirementOf(guardrail, scope);
21
51
  for (const { resourceArns, conditions } of statements) {
22
52
  aws_iam_1.Grant.addToPrincipal({
23
53
  grantee,
24
- actions: INVOKE_ACTIONS,
54
+ actions,
25
55
  resourceArns,
26
- conditions: identifier
27
- ? {
28
- ...conditions,
29
- StringEquals: {
30
- ...conditions?.StringEquals,
31
- "bedrock:GuardrailIdentifier": identifier,
32
- },
33
- }
34
- : conditions,
56
+ conditions: required ? withGuardrail(conditions, required) : conditions,
35
57
  });
36
58
  }
37
- if (!guardrail)
59
+ if (!required)
38
60
  return;
39
61
  grantee.grantPrincipal.addToPrincipalPolicy(new aws_iam_1.PolicyStatement({
40
62
  effect: aws_iam_1.Effect.DENY,
41
- actions: INVOKE_ACTIONS,
63
+ actions,
42
64
  resources: statements.flatMap((s) => s.resourceArns),
43
- conditions: { StringNotEquals: { "bedrock:GuardrailIdentifier": identifierOf(guardrail) } },
65
+ conditions: {
66
+ [required.like ? "StringNotLike" : "StringNotEquals"]: {
67
+ "bedrock:GuardrailIdentifier": required.identifier,
68
+ },
69
+ },
44
70
  }));
45
- grantApply(guardrail, grantee);
71
+ grantApply(required.applyArn, grantee);
46
72
  }
47
- function grantApply(guardrail, grantee) {
73
+ function grantApply(guardrailArn, grantee) {
48
74
  aws_iam_1.Grant.addToPrincipal({
49
75
  grantee,
50
76
  actions: ["bedrock:ApplyGuardrail"],
51
- resourceArns: [guardrail.guardrailArn],
77
+ resourceArns: [guardrailArn],
52
78
  });
53
79
  }
54
80
  /**
@@ -65,15 +91,15 @@ exports.modelGrants = {
65
91
  * Invoke the target through `InvokeModel`, `Converse` or their streaming
66
92
  * variants.
67
93
  *
68
- * For a cross-Region profile this also grants the foundation model in the
69
- * source Region and every Region the profile routes to, conditioned on
70
- * `bedrock:InferenceProfileArn` so those models are reachable only through
71
- * the profile.
94
+ * For a cross-Region profile this also grants the foundation model, in
95
+ * every Region or in the profile's listed `routingRegions`, conditioned on
96
+ * `bedrock:InferenceProfileArn` so the model is reachable only through the
97
+ * profile.
72
98
  *
73
99
  * @see https://docs.aws.amazon.com/wellarchitected/latest/generative-ai-lens/gensec01-bp01.html
74
100
  */
75
- invoke: (target, { requireGuardrail } = {}) => (0, core_1.grantVia)((0, core_1.combine)({ target, guardrail: requireGuardrail }), ({ target: resolved, guardrail }, grantee) => {
76
- grantInvoke(resolved, grantee, guardrail);
101
+ invoke: (target, { requireGuardrail, streaming = true } = {}) => (0, core_1.grantVia)((0, core_1.combine)({ target, guardrail: requireGuardrail }), ({ target: resolved, guardrail }, grantee) => {
102
+ grantInvoke(resolved, grantee, guardrail, streaming);
77
103
  }),
78
104
  };
79
105
  /**
@@ -87,7 +113,19 @@ exports.guardrailGrants = {
87
113
  * `ApplyGuardrail` API or a model invocation that names it.
88
114
  */
89
115
  apply: (guardrail) => (0, core_1.grantVia)(guardrail, (resolved, grantee) => {
90
- grantApply(resolved, grantee);
116
+ grantApply(resolved.guardrailArn, grantee);
117
+ }),
118
+ /**
119
+ * Apply any guardrail in the grantee's account and Region, for a caller
120
+ * that may name one at run time. Where the guardrail is known, `apply` it;
121
+ * where every call must carry one, `modelGrants.invoke(…, { requireGuardrail })`.
122
+ */
123
+ // A plain Grant rather than grantVia: there is no resource to resolve, only
124
+ // the grantee's own account and Region.
125
+ applyAny: () => ({
126
+ applyTo(grantee) {
127
+ grantApply(anyGuardrailArn((0, inference_target_js_1.scopeOf)(grantee.grantPrincipal)), grantee);
128
+ },
91
129
  }),
92
130
  };
93
131
  //# sourceMappingURL=grants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"grants.js","sourceRoot":"","sources":["../../src/grants.ts"],"names":[],"mappings":";;;AAAA,iDAAkG;AAClG,6CAAoF;AAEpF,+DAA4F;AAE5F;;;;;GAKG;AACH,MAAM,cAAc,GAAG,CAAC,qBAAqB,EAAE,uCAAuC,CAAC,CAAC;AAcxF,sEAAsE;AACtE,SAAS,YAAY,CAAC,SAA6B;IACjD,OAAO,GAAG,SAAS,CAAC,YAAY,IAAI,SAAS,CAAC,OAAO,EAAE,CAAC;AAC1D,CAAC;AAED,SAAS,WAAW,CAClB,MAAuB,EACvB,OAAmB,EACnB,SAAyC;IAEzC,MAAM,UAAU,GAAG,IAAA,0CAAoB,EAAC,MAAM,EAAE,IAAA,6BAAO,EAAC,OAAO,CAAC,cAAc,CAAC,CAA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QACpD,UAAU,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC,CAAC;IACJ;;;;OAIG;IACH,4EAA4E;IAC5E,wCAAwC;IACxC,QAAQ,EAAE,GAAsB,EAAE,CAAC,CAAC;QAClC,OAAO,CAAC,OAAO;YACb,UAAU,CAAC,eAAe,CAAC,IAAA,6BAAO,EAAC,OAAO,CAAC,cAAc,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QACxE,CAAC;KACF,CAAC;CACH,CAAC"}
@@ -1,6 +1,6 @@
1
1
  export { type ApplicationInferenceProfileBuilderProps, type ApplicationInferenceProfileBuilderResult, createApplicationInferenceProfileBuilder, type IApplicationInferenceProfileBuilder, } from "./application-inference-profile-builder.js";
2
2
  export { type ApplicationInferenceProfile, foundationModelFor, type GeographicInferenceProfile, type GeographicInferenceProfileOptions, type GlobalInferenceProfile, INFERENCE_PROFILE_GEOGRAPHIES, type InferenceProfile, type InferenceProfileGeography, inferenceProfile, } from "./inference-profile.js";
3
- export { type InferenceTarget, invocationArns } from "./inference-target.js";
3
+ export { type InferenceTarget, type InferenceTargetIdOptions, inferenceTarget, invocationArns, } from "./inference-target.js";
4
4
  export { guardrailGrants, type ModelInvokeGrantOptions, modelGrants } from "./grants.js";
5
5
  export { createGuardrailBuilder, type GuardrailBuilderProps, type GuardrailBuilderResult, type GuardrailReference, type IGuardrailBuilder, } from "./guardrail-builder.js";
6
6
  export { GUARDRAIL_DEFAULTS } from "./guardrail-defaults.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,uCAAuC,EAC5C,KAAK,wCAAwC,EAC7C,wCAAwC,EACxC,KAAK,mCAAmC,GACzC,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACL,KAAK,2BAA2B,EAChC,kBAAkB,EAClB,KAAK,0BAA0B,EAC/B,KAAK,iCAAiC,EACtC,KAAK,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CAAuC,EACvC,KAAK,iCAAiC,GACvC,MAAM,sCAAsC,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MODEL_INVOCATION_LOGGING_ALARM_DEFAULTS = exports.MODEL_INVOCATION_LOGGING_DEFAULTS = exports.createModelInvocationLoggingBuilder = exports.modelMetrics = exports.MODEL_ALARM_DEFAULTS = exports.createModelAlarmBuilder = exports.guardrailMetrics = exports.GUARDRAIL_DEFAULTS = exports.createGuardrailBuilder = exports.modelGrants = exports.guardrailGrants = exports.invocationArns = exports.inferenceProfile = exports.INFERENCE_PROFILE_GEOGRAPHIES = exports.foundationModelFor = exports.createApplicationInferenceProfileBuilder = void 0;
3
+ exports.MODEL_INVOCATION_LOGGING_ALARM_DEFAULTS = exports.MODEL_INVOCATION_LOGGING_DEFAULTS = exports.createModelInvocationLoggingBuilder = exports.modelMetrics = exports.MODEL_ALARM_DEFAULTS = exports.createModelAlarmBuilder = exports.guardrailMetrics = exports.GUARDRAIL_DEFAULTS = exports.createGuardrailBuilder = exports.modelGrants = exports.guardrailGrants = exports.invocationArns = exports.inferenceTarget = exports.inferenceProfile = exports.INFERENCE_PROFILE_GEOGRAPHIES = exports.foundationModelFor = exports.createApplicationInferenceProfileBuilder = void 0;
4
4
  var application_inference_profile_builder_js_1 = require("./application-inference-profile-builder.js");
5
5
  Object.defineProperty(exports, "createApplicationInferenceProfileBuilder", { enumerable: true, get: function () { return application_inference_profile_builder_js_1.createApplicationInferenceProfileBuilder; } });
6
6
  var inference_profile_js_1 = require("./inference-profile.js");
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "foundationModelFor", { enumerable: true, get: fu
8
8
  Object.defineProperty(exports, "INFERENCE_PROFILE_GEOGRAPHIES", { enumerable: true, get: function () { return inference_profile_js_1.INFERENCE_PROFILE_GEOGRAPHIES; } });
9
9
  Object.defineProperty(exports, "inferenceProfile", { enumerable: true, get: function () { return inference_profile_js_1.inferenceProfile; } });
10
10
  var inference_target_js_1 = require("./inference-target.js");
11
+ Object.defineProperty(exports, "inferenceTarget", { enumerable: true, get: function () { return inference_target_js_1.inferenceTarget; } });
11
12
  Object.defineProperty(exports, "invocationArns", { enumerable: true, get: function () { return inference_target_js_1.invocationArns; } });
12
13
  var grants_js_1 = require("./grants.js");
13
14
  Object.defineProperty(exports, "guardrailGrants", { enumerable: true, get: function () { return grants_js_1.guardrailGrants; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,uGAKoD;AAFlD,oKAAA,wCAAwC,OAAA;AAG1C,+DAUgC;AAR9B,0HAAA,kBAAkB,OAAA;AAIlB,qIAAA,6BAA6B,OAAA;AAG7B,wHAAA,gBAAgB,OAAA;AAElB,6DAA6E;AAA9C,qHAAA,cAAc,OAAA;AAC7C,yCAAyF;AAAhF,4GAAA,eAAe,OAAA;AAAgC,wGAAA,WAAW,OAAA;AACnE,+DAMgC;AAL9B,8HAAA,sBAAsB,OAAA;AAMxB,iEAA6D;AAApD,2HAAA,kBAAkB,OAAA;AAC3B,6DAI+B;AAD7B,uHAAA,gBAAgB,OAAA;AAElB,mEAKkC;AAJhC,iIAAA,uBAAuB,OAAA;AAMzB,qEAAiE;AAAxD,+HAAA,oBAAoB,OAAA;AAC7B,qDAA2F;AAAxC,+GAAA,YAAY,OAAA;AAC/D,6FAO+C;AAN7C,0JAAA,mCAAmC,OAAA;AAEnC,wJAAA,iCAAiC,OAAA;AAKnC,2FAG8C;AAF5C,6JAAA,uCAAuC,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,uGAKoD;AAFlD,oKAAA,wCAAwC,OAAA;AAG1C,+DAUgC;AAR9B,0HAAA,kBAAkB,OAAA;AAIlB,qIAAA,6BAA6B,OAAA;AAG7B,wHAAA,gBAAgB,OAAA;AAElB,6DAK+B;AAF7B,sHAAA,eAAe,OAAA;AACf,qHAAA,cAAc,OAAA;AAEhB,yCAAyF;AAAhF,4GAAA,eAAe,OAAA;AAAgC,wGAAA,WAAW,OAAA;AACnE,+DAMgC;AAL9B,8HAAA,sBAAsB,OAAA;AAMxB,iEAA6D;AAApD,2HAAA,kBAAkB,OAAA;AAC3B,6DAI+B;AAD7B,uHAAA,gBAAgB,OAAA;AAElB,mEAKkC;AAJhC,iIAAA,uBAAuB,OAAA;AAMzB,qEAAiE;AAAxD,+HAAA,oBAAoB,OAAA;AAC7B,qDAA2F;AAAxC,+GAAA,YAAY,OAAA;AAC/D,6FAO+C;AAN7C,0JAAA,mCAAmC,OAAA;AAEnC,wJAAA,iCAAiC,OAAA;AAKnC,2FAG8C;AAF5C,6JAAA,uCAAuC,OAAA"}
@@ -9,7 +9,7 @@ import { FoundationModelIdentifier } from "aws-cdk-lib/aws-bedrock";
9
9
  *
10
10
  * @see https://docs.aws.amazon.com/bedrock/latest/userguide/geographic-cross-region-inference.html
11
11
  */
12
- export declare const INFERENCE_PROFILE_GEOGRAPHIES: readonly ["us", "eu", "apac", "jp", "au", "us-gov"];
12
+ export declare const INFERENCE_PROFILE_GEOGRAPHIES: readonly ["us", "eu", "apac", "jp", "au", "in", "us-gov"];
13
13
  /** A known geography prefix. See {@link INFERENCE_PROFILE_GEOGRAPHIES}. */
14
14
  export type InferenceProfileGeography = (typeof INFERENCE_PROFILE_GEOGRAPHIES)[number];
15
15
  /**
@@ -26,11 +26,18 @@ export interface GeographicInferenceProfile {
26
26
  /** The id to invoke, e.g. `eu.anthropic.claude-haiku-4-5-20251001-v1:0`. */
27
27
  readonly profileId: string;
28
28
  /**
29
- * Every Region the profile may route to from the source Region, as listed
30
- * by `aws bedrock get-inference-profile` or the model's page in the Bedrock
31
- * user guide. The source Region is always granted, listed or not.
29
+ * The Regions the profile routes to from the source Region, as listed by
30
+ * `aws bedrock get-inference-profile`. AWS chooses and extends that list,
31
+ * so a copy of it is a snapshot. Bedrock checks the model in every Region
32
+ * the profile may route to, so once AWS adds one, a grant built from the
33
+ * copy denies every call through the profile.
34
+ *
35
+ * Omitted, the grant covers the foundation model in every Region, still
36
+ * only through this profile. List the Regions when the policy must name
37
+ * each one, for a service control policy or a policy scanner. The source
38
+ * Region is always granted.
32
39
  */
33
- readonly routingRegions: readonly string[];
40
+ readonly routingRegions?: readonly string[];
34
41
  }
35
42
  /**
36
43
  * A system-defined inference profile that routes requests to any supported
@@ -68,10 +75,20 @@ export interface ApplicationInferenceProfile {
68
75
  }
69
76
  /** Options for {@link inferenceProfile.geographic}. */
70
77
  export type GeographicInferenceProfileOptions = Pick<GeographicInferenceProfile, "model" | "geography" | "routingRegions">;
78
+ /**
79
+ * The segment of `id` before its first dot, and whether it marks a
80
+ * system-defined profile id. Undefined when `id` has no such segment.
81
+ * @internal
82
+ */
83
+ export declare function idPrefix(id: string): {
84
+ prefix: string;
85
+ isProfile: boolean;
86
+ } | undefined;
87
+ /** Throws unless `id` is a non-empty literal string. @internal */
88
+ export declare function assertLiteralId(id: string, label: string): void;
71
89
  declare function geographic(options: GeographicInferenceProfileOptions): GeographicInferenceProfile;
72
90
  declare function global(model: FoundationModelIdentifier): GlobalInferenceProfile;
73
- declare function parse(profileId: string): GlobalInferenceProfile;
74
- declare function parse(profileId: string, routingRegions: readonly string[]): InferenceProfile;
91
+ declare function parse(profileId: string, routingRegions?: readonly string[]): InferenceProfile;
75
92
  /**
76
93
  * Factories for {@link InferenceProfile} values.
77
94
  *
@@ -80,7 +97,6 @@ declare function parse(profileId: string, routingRegions: readonly string[]): In
80
97
  * const haiku = inferenceProfile.geographic({
81
98
  * model: FoundationModelIdentifier.ANTHROPIC_CLAUDE_HAIKU_4_5_20251001_V1_0,
82
99
  * geography: "eu",
83
- * routingRegions: ["eu-central-1", "eu-north-1", "eu-south-1", "eu-south-2", "eu-west-1", "eu-west-3"],
84
100
  * });
85
101
  * haiku.profileId; // "eu.anthropic.claude-haiku-4-5-20251001-v1:0"
86
102
  * ```
@@ -93,7 +109,7 @@ export declare const inferenceProfile: {
93
109
  /**
94
110
  * Reads a profile id such as `eu.anthropic.claude-haiku-4-5-20251001-v1:0`.
95
111
  * Throws unless the id starts with a known geography or `global`. A
96
- * geographic id needs its `routingRegions`; a global id takes none.
112
+ * geographic id may take its `routingRegions`; a global id takes none.
97
113
  */
98
114
  parse: typeof parse;
99
115
  };
@@ -1 +1 @@
1
- {"version":3,"file":"inference-profile.d.ts","sourceRoot":"","sources":["../../src/inference-profile.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAEpE;;;;;;;;;GASG;AACH,eAAO,MAAM,6BAA6B,qDAAsD,CAAC;AAEjG,2EAA2E;AAC3E,MAAM,MAAM,yBAAyB,GAAG,CAAC,OAAO,6BAA6B,CAAC,CAAC,MAAM,CAAC,CAAC;AAIvF;;;;;GAKG;AACH,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,yBAAyB,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;IAC9D,+CAA+C;IAC/C,QAAQ,CAAC,KAAK,EAAE,yBAAyB,CAAC;IAC1C,4EAA4E;IAC5E,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B;;;;OAIG;IACH,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;CAC5C;AAED;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,+CAA+C;IAC/C,QAAQ,CAAC,KAAK,EAAE,yBAAyB,CAAC;IAC1C,gFAAgF;IAChF,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,uDAAuD;AACvD,MAAM,MAAM,gBAAgB,GAAG,0BAA0B,GAAG,sBAAsB,CAAC;AAEnF;;;;;;GAMG;AACH,MAAM,WAAW,2BAA2B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