@composurecdk/bedrock 0.11.0 → 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 +3 -3
@@ -1,51 +1,77 @@
1
1
  import { Effect, Grant as IamGrant, PolicyStatement } from "aws-cdk-lib/aws-iam";
2
2
  import { combine, grantVia } from "@composurecdk/core";
3
- import { invocationStatements, scopeOf } from "./inference-target.js";
3
+ import { bedrockArn, environmentOf } from "./arn.js";
4
+ import { invocationStatements, scopeOf, } from "./inference-target.js";
5
+ const INVOKE_ACTION = "bedrock:InvokeModel";
4
6
  /**
5
7
  * Streaming operations (`InvokeModelWithResponseStream`, `ConverseStream`)
6
8
  * require both actions.
7
9
  *
8
10
  * @see https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonbedrock.html
9
11
  */
10
- const INVOKE_ACTIONS = ["bedrock:InvokeModel", "bedrock:InvokeModelWithResponseStream"];
11
- /** The versioned identifier `bedrock:GuardrailIdentifier` carries. */
12
- function identifierOf(guardrail) {
13
- return `${guardrail.guardrailArn}:${guardrail.version}`;
12
+ const INVOKE_ACTIONS = [INVOKE_ACTION, "bedrock:InvokeModelWithResponseStream"];
13
+ /**
14
+ * Every guardrail in `scope`'s account and Region. The versioned identifiers
15
+ * `bedrock:GuardrailIdentifier` carries (`…:guardrail/<id>:<version>`) match
16
+ * it as a `StringLike` pattern.
17
+ */
18
+ function anyGuardrailArn(scope) {
19
+ const { partition, region, account } = environmentOf(scope);
20
+ return bedrockArn(partition, "guardrail", "*", region, account);
21
+ }
22
+ function requirementOf(guardrail, scope) {
23
+ if (guardrail === "any") {
24
+ const arn = anyGuardrailArn(scope);
25
+ return { like: true, identifier: arn, applyArn: arn };
26
+ }
27
+ return {
28
+ like: false,
29
+ identifier: `${guardrail.guardrailArn}:${guardrail.version}`,
30
+ applyArn: guardrail.guardrailArn,
31
+ };
14
32
  }
15
- function grantInvoke(target, grantee, guardrail) {
16
- const statements = invocationStatements(target, scopeOf(grantee.grantPrincipal));
17
- const identifier = guardrail && identifierOf(guardrail);
33
+ function withGuardrail(conditions, required) {
34
+ const match = required.like ? "StringLike" : "StringEquals";
35
+ return {
36
+ ...conditions,
37
+ [match]: {
38
+ ...conditions?.[match],
39
+ "bedrock:GuardrailIdentifier": required.identifier,
40
+ },
41
+ };
42
+ }
43
+ function grantInvoke(target, grantee, guardrail, streaming) {
44
+ const scope = scopeOf(grantee.grantPrincipal);
45
+ const actions = streaming ? INVOKE_ACTIONS : [INVOKE_ACTION];
46
+ const statements = invocationStatements(target, scope);
47
+ const required = guardrail && requirementOf(guardrail, scope);
18
48
  for (const { resourceArns, conditions } of statements) {
19
49
  IamGrant.addToPrincipal({
20
50
  grantee,
21
- actions: INVOKE_ACTIONS,
51
+ actions,
22
52
  resourceArns,
23
- conditions: identifier
24
- ? {
25
- ...conditions,
26
- StringEquals: {
27
- ...conditions?.StringEquals,
28
- "bedrock:GuardrailIdentifier": identifier,
29
- },
30
- }
31
- : conditions,
53
+ conditions: required ? withGuardrail(conditions, required) : conditions,
32
54
  });
33
55
  }
34
- if (!guardrail)
56
+ if (!required)
35
57
  return;
36
58
  grantee.grantPrincipal.addToPrincipalPolicy(new PolicyStatement({
37
59
  effect: Effect.DENY,
38
- actions: INVOKE_ACTIONS,
60
+ actions,
39
61
  resources: statements.flatMap((s) => s.resourceArns),
40
- conditions: { StringNotEquals: { "bedrock:GuardrailIdentifier": identifierOf(guardrail) } },
62
+ conditions: {
63
+ [required.like ? "StringNotLike" : "StringNotEquals"]: {
64
+ "bedrock:GuardrailIdentifier": required.identifier,
65
+ },
66
+ },
41
67
  }));
42
- grantApply(guardrail, grantee);
68
+ grantApply(required.applyArn, grantee);
43
69
  }
44
- function grantApply(guardrail, grantee) {
70
+ function grantApply(guardrailArn, grantee) {
45
71
  IamGrant.addToPrincipal({
46
72
  grantee,
47
73
  actions: ["bedrock:ApplyGuardrail"],
48
- resourceArns: [guardrail.guardrailArn],
74
+ resourceArns: [guardrailArn],
49
75
  });
50
76
  }
51
77
  /**
@@ -62,15 +88,15 @@ export const modelGrants = {
62
88
  * Invoke the target through `InvokeModel`, `Converse` or their streaming
63
89
  * variants.
64
90
  *
65
- * For a cross-Region profile this also grants the foundation model in the
66
- * source Region and every Region the profile routes to, conditioned on
67
- * `bedrock:InferenceProfileArn` so those models are reachable only through
68
- * the profile.
91
+ * For a cross-Region profile this also grants the foundation model, in
92
+ * every Region or in the profile's listed `routingRegions`, conditioned on
93
+ * `bedrock:InferenceProfileArn` so the model is reachable only through the
94
+ * profile.
69
95
  *
70
96
  * @see https://docs.aws.amazon.com/wellarchitected/latest/generative-ai-lens/gensec01-bp01.html
71
97
  */
72
- invoke: (target, { requireGuardrail } = {}) => grantVia(combine({ target, guardrail: requireGuardrail }), ({ target: resolved, guardrail }, grantee) => {
73
- grantInvoke(resolved, grantee, guardrail);
98
+ invoke: (target, { requireGuardrail, streaming = true } = {}) => grantVia(combine({ target, guardrail: requireGuardrail }), ({ target: resolved, guardrail }, grantee) => {
99
+ grantInvoke(resolved, grantee, guardrail, streaming);
74
100
  }),
75
101
  };
76
102
  /**
@@ -84,7 +110,19 @@ export const guardrailGrants = {
84
110
  * `ApplyGuardrail` API or a model invocation that names it.
85
111
  */
86
112
  apply: (guardrail) => grantVia(guardrail, (resolved, grantee) => {
87
- grantApply(resolved, grantee);
113
+ grantApply(resolved.guardrailArn, grantee);
114
+ }),
115
+ /**
116
+ * Apply any guardrail in the grantee's account and Region, for a caller
117
+ * that may name one at run time. Where the guardrail is known, `apply` it;
118
+ * where every call must carry one, `modelGrants.invoke(…, { requireGuardrail })`.
119
+ */
120
+ // A plain Grant rather than grantVia: there is no resource to resolve, only
121
+ // the grantee's own account and Region.
122
+ applyAny: () => ({
123
+ applyTo(grantee) {
124
+ grantApply(anyGuardrailArn(scopeOf(grantee.grantPrincipal)), grantee);
125
+ },
88
126
  }),
89
127
  };
90
128
  //# sourceMappingURL=grants.js.map
@@ -1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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,sBAAsB,EAC3B,6BAA6B,EAC7B,KAAK,gBAAgB,EACrB,KAAK,yBAAyB,EAC9B,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,KAAK,eAAe,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,KAAK,uBAAuB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACzF,OAAO,EACL,sBAAsB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,GACvB,MAAM,wBAAw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EAAE,KAAK,uBAAuB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACzF,OAAO,EACL,sBAAsB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,GACvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,uBAAuB,EACvB,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,GAC7B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACvF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC3F,OAAO,EACL,mCAAmC,EACnC,KAAK,8BAA8B,EACnC,iCAAiC,EACjC,KAAK,kCAAkC,EACvC,KAAK,mCAAmC,EACxC,KAAK,gCAAgC,GACtC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,uCAAuC,EACvC,KAAK,iCAAiC,GACvC,MAAM,sCAAsC,CAAC"}
package/dist/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export { createApplicationInferenceProfileBuilder, } from "./application-inference-profile-builder.js";
2
2
  export { foundationModelFor, INFERENCE_PROFILE_GEOGRAPHIES, inferenceProfile, } from "./inference-profile.js";
3
- export { invocationArns } from "./inference-target.js";
3
+ export { inferenceTarget, invocationArns, } from "./inference-target.js";
4
4
  export { guardrailGrants, modelGrants } from "./grants.js";
5
5
  export { createGuardrailBuilder, } from "./guardrail-builder.js";
6
6
  export { GUARDRAIL_DEFAULTS } from "./guardrail-defaults.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,wCAAwC,GAEzC,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAEL,kBAAkB,EAIlB,6BAA6B,EAG7B,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAwB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAgC,WAAW,EAAE,MAAM,aAAa,CAAC;AACzF,OAAO,EACL,sBAAsB,GAKvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAGL,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,uBAAuB,GAIxB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAA4C,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC3F,OAAO,EACL,mCAAmC,EAEnC,iCAAiC,GAIlC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,uCAAuC,GAExC,MAAM,sCAAsC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,wCAAwC,GAEzC,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAEL,kBAAkB,EAIlB,6BAA6B,EAG7B,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAGL,eAAe,EACf,cAAc,GACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAgC,WAAW,EAAE,MAAM,aAAa,CAAC;AACzF,OAAO,EACL,sBAAsB,GAKvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAGL,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,uBAAuB,GAIxB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAA4C,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC3F,OAAO,EACL,mCAAmC,EAEnC,iCAAiC,GAIlC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,uCAAuC,GAExC,MAAM,sCAAsC,CAAC"}
@@ -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;IAC1C,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,6DAA6D;IAC7D,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM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GxE;AAcD,iBAAS,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,gBAAgB,CAYtF;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gBAAgB;IAC3B,8CAA8C;;IAE9C,4DAA4D;;IAE5D;;;;OAIG;;CAEJ,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,yBAAyB,CAE/E"}
@@ -10,32 +10,48 @@ import { FoundationModelIdentifier } from "aws-cdk-lib/aws-bedrock";
10
10
  *
11
11
  * @see https://docs.aws.amazon.com/bedrock/latest/userguide/geographic-cross-region-inference.html
12
12
  */
13
- export const INFERENCE_PROFILE_GEOGRAPHIES = ["us", "eu", "apac", "jp", "au", "us-gov"];
13
+ export const INFERENCE_PROFILE_GEOGRAPHIES = [
14
+ "us",
15
+ "eu",
16
+ "apac",
17
+ "jp",
18
+ "au",
19
+ "in",
20
+ "us-gov",
21
+ ];
14
22
  const GLOBAL_PREFIX = "global";
23
+ const PROFILE_PREFIXES = [GLOBAL_PREFIX, ...INFERENCE_PROFILE_GEOGRAPHIES];
15
24
  const GEOGRAPHY_PATTERN = /^[a-z]+(-[a-z]+)*$/;
16
25
  const REGION_PATTERN = /^[a-z]{2}(-[a-z]+)+-\d+$/;
17
- function isProfilePrefix(prefix) {
18
- return (prefix === GLOBAL_PREFIX ||
19
- INFERENCE_PROFILE_GEOGRAPHIES.includes(prefix));
20
- }
21
- function prefixOf(id) {
26
+ /**
27
+ * The segment of `id` before its first dot, and whether it marks a
28
+ * system-defined profile id. Undefined when `id` has no such segment.
29
+ * @internal
30
+ */
31
+ export function idPrefix(id) {
22
32
  const dot = id.indexOf(".");
23
- return dot > 0 ? id.slice(0, dot) : undefined;
33
+ if (dot <= 0)
34
+ return undefined;
35
+ const prefix = id.slice(0, dot);
36
+ return { prefix, isProfile: PROFILE_PREFIXES.includes(prefix) };
37
+ }
38
+ /** Throws unless `id` is a non-empty literal string. @internal */
39
+ export function assertLiteralId(id, label) {
40
+ if (Token.isUnresolved(id) || id === "") {
41
+ throw new Error(`${label} must be a non-empty literal string.`);
42
+ }
24
43
  }
25
44
  function assertModel(model) {
26
45
  const { modelId } = model;
27
- if (Token.isUnresolved(modelId) || modelId === "") {
28
- throw new Error("Inference profile model id must be a non-empty literal string.");
29
- }
30
- const prefix = prefixOf(modelId);
31
- if (prefix !== undefined && isProfilePrefix(prefix)) {
46
+ assertLiteralId(modelId, "Inference profile model id");
47
+ if (idPrefix(modelId)?.isProfile) {
32
48
  throw new Error(`"${modelId}" is an inference profile id, not a foundation model id. ` +
33
- `Use inferenceProfile.parse("${modelId}", …) instead.`);
49
+ `Use inferenceProfile.parse("${modelId}") instead.`);
34
50
  }
35
51
  }
36
52
  function assertRoutingRegions(profileId, regions) {
37
53
  if (regions.length === 0) {
38
- throw new Error(`Inference profile "${profileId}": routingRegions must not be empty.`);
54
+ throw new Error(`Inference profile "${profileId}": routingRegions must not be empty; omit it to grant every Region.`);
39
55
  }
40
56
  for (const region of regions) {
41
57
  if (Token.isUnresolved(region) || !REGION_PATTERN.test(region)) {
@@ -44,19 +60,20 @@ function assertRoutingRegions(profileId, regions) {
44
60
  }
45
61
  }
46
62
  function geographic(options) {
47
- const { model, geography } = options;
63
+ const { model, geography, routingRegions } = options;
48
64
  assertModel(model);
49
65
  if (geography === GLOBAL_PREFIX || !GEOGRAPHY_PATTERN.test(geography)) {
50
66
  throw new Error(`"${geography}" is not a geography prefix. Use inferenceProfile.global() for a global profile.`);
51
67
  }
52
68
  const profileId = `${geography}.${model.modelId}`;
53
- assertRoutingRegions(profileId, options.routingRegions);
69
+ if (routingRegions !== undefined)
70
+ assertRoutingRegions(profileId, routingRegions);
54
71
  return Object.freeze({
55
72
  kind: "geographic",
56
73
  geography,
57
74
  model,
58
75
  profileId,
59
- routingRegions: Object.freeze([...new Set(options.routingRegions)]),
76
+ ...(routingRegions && { routingRegions: Object.freeze([...new Set(routingRegions)]) }),
60
77
  });
61
78
  }
62
79
  function global(model) {
@@ -64,11 +81,12 @@ function global(model) {
64
81
  return Object.freeze({ kind: "global", model, profileId: `${GLOBAL_PREFIX}.${model.modelId}` });
65
82
  }
66
83
  function splitProfileId(profileId) {
67
- const prefix = prefixOf(profileId);
68
- if (prefix === undefined || !isProfilePrefix(prefix)) {
84
+ const parsed = idPrefix(profileId);
85
+ if (!parsed?.isProfile) {
69
86
  throw new Error(`"${profileId}" is not a system-defined inference profile id. Expected one of the ` +
70
- `prefixes: ${[GLOBAL_PREFIX, ...INFERENCE_PROFILE_GEOGRAPHIES].join(", ")}.`);
87
+ `prefixes: ${PROFILE_PREFIXES.join(", ")}.`);
71
88
  }
89
+ const { prefix } = parsed;
72
90
  return { prefix, modelId: profileId.slice(prefix.length + 1) };
73
91
  }
74
92
  function parse(profileId, routingRegions) {
@@ -80,9 +98,6 @@ function parse(profileId, routingRegions) {
80
98
  }
81
99
  return global(model);
82
100
  }
83
- if (routingRegions === undefined) {
84
- throw new Error(`Inference profile "${profileId}" is geographic and needs its routingRegions.`);
85
- }
86
101
  return geographic({ model, geography: prefix, routingRegions });
87
102
  }
88
103
  /**
@@ -93,7 +108,6 @@ function parse(profileId, routingRegions) {
93
108
  * const haiku = inferenceProfile.geographic({
94
109
  * model: FoundationModelIdentifier.ANTHROPIC_CLAUDE_HAIKU_4_5_20251001_V1_0,
95
110
  * geography: "eu",
96
- * routingRegions: ["eu-central-1", "eu-north-1", "eu-south-1", "eu-south-2", "eu-west-1", "eu-west-3"],
97
111
  * });
98
112
  * haiku.profileId; // "eu.anthropic.claude-haiku-4-5-20251001-v1:0"
99
113
  * ```
@@ -106,7 +120,7 @@ export const inferenceProfile = {
106
120
  /**
107
121
  * Reads a profile id such as `eu.anthropic.claude-haiku-4-5-20251001-v1:0`.
108
122
  * Throws unless the id starts with a known geography or `global`. A
109
- * geographic id needs its `routingRegions`; a global id takes none.
123
+ * geographic id may take its `routingRegions`; a global id takes none.
110
124
  */
111
125
  parse,
112
126
  };
@@ -1 +1 @@
1
- {"version":3,"file":"inference-profile.js","sourceRoot":"","sources":["../../src/inference-profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAEpE;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAU,CAAC;AAKjG,MAAM,aAAa,GAAG,QAAQ,CAAC;AAkE/B,MAAM,iBAAiB,GAAG,oBAAoB,CAAC;AAC/C,MAAM,cAAc,GAAG,0BAA0B,CAAC;AAElD,SAAS,eAAe,CAAC,MAAc;IACrC,OAAO,CACL,MAAM,KAAK,aAAa;QACvB,6BAAmD,CAAC,QAAQ,CAAC,MAAM,CAAC,CACtE,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,EAAU;IAC1B,MAAM,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5B,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAChD,CAAC;AAED,SAAS,WAAW,CAAC,KAAgC;IACnD,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAC1B,IAAI,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC;QAClD,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;IACpF,CAAC;IACD,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;IACjC,IAAI,MAAM,KAAK,SAAS,IAAI,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC;QACpD,MAAM,IAAI,KAA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ACtD,MAAM,KAAK,GAAG,IAAI,yBAAyB,CAAC,OAAO,CAAC,CAAC;IACrD,IAAI,MAAM,KAAK,aAAa,EAAE,CAAC;QAC7B,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CACb,sBAAsB,SAAS,wEAAwE,CACxG,CAAC;QACJ,CAAC;QACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IACD,OAAO,UAAU,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC,CAAC;AAClE,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,8CAA8C;IAC9C,UAAU;IACV,4DAA4D;IAC5D,MAAM;IACN;;;;OAIG;IACH,KAAK;CACN,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,SAAiB;IAClD,OAAO,IAAI,yBAAyB,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC;AAC1E,CAAC"}
@@ -1,6 +1,6 @@
1
- import type { FoundationModelIdentifier, IModel } from "aws-cdk-lib/aws-bedrock";
1
+ import { FoundationModelIdentifier, type IModel } from "aws-cdk-lib/aws-bedrock";
2
2
  import { type IConstruct } from "constructs";
3
- import type { ApplicationInferenceProfile, InferenceProfile } from "./inference-profile.js";
3
+ import { type ApplicationInferenceProfile, type InferenceProfile } from "./inference-profile.js";
4
4
  /**
5
5
  * Anything a caller can invoke: an in-Region foundation model, a
6
6
  * system-defined or application inference profile, or any {@link IModel} (a
@@ -17,7 +17,9 @@ export interface InvocationStatement {
17
17
  /**
18
18
  * The statements for invoking `target` from the Region `scope` deploys to:
19
19
  * those the Bedrock user guide prescribes, and for an application profile the
20
- * shape verified against live IAM.
20
+ * shape verified against live IAM. A geographic profile without
21
+ * `routingRegions` grants the model in every Region rather than an
22
+ * enumerated list, still only through the profile (#628).
21
23
  *
22
24
  * @see https://docs.aws.amazon.com/bedrock/latest/userguide/geographic-cross-region-inference.html#geographic-cris-iam-setup
23
25
  * @see https://docs.aws.amazon.com/bedrock/latest/userguide/global-cross-region-inference.html#global-cris-iam-setup
@@ -37,7 +39,9 @@ export declare function sourceArn(source: FoundationModelIdentifier | InferenceP
37
39
  *
38
40
  * {@link modelGrants.invoke} applies these with the conditions the Bedrock
39
41
  * user guide prescribes; use this list where you write a policy yourself,
40
- * such as a service control policy.
42
+ * such as a service control policy. A geographic profile without
43
+ * `routingRegions` yields one Region-wildcard model ARN, so list the Regions
44
+ * on the profile when the policy must name each one.
41
45
  *
42
46
  * @param scope - Resolves partition, Region and account from its stack. Omit
43
47
  * for the `AWS::` pseudo-parameters.
@@ -45,4 +49,38 @@ export declare function sourceArn(source: FoundationModelIdentifier | InferenceP
45
49
  export declare function invocationArns(target: InferenceTarget, scope?: IConstruct): string[];
46
50
  /** @internal */
47
51
  export declare function scopeOf(principal: unknown): IConstruct | undefined;
52
+ /** Options for {@link inferenceTarget.fromId}. */
53
+ export interface InferenceTargetIdOptions {
54
+ /** For a geographic profile id: see {@link GeographicInferenceProfile.routingRegions}. */
55
+ readonly routingRegions?: readonly string[];
56
+ }
57
+ /**
58
+ * Resolves an id that arrives as a string, such as from configuration, to the
59
+ * target it names:
60
+ *
61
+ * - `anthropic.claude-…` → a `FoundationModelIdentifier`;
62
+ * - `eu.anthropic.claude-…` or `global.anthropic.claude-…` → a system-defined
63
+ * profile, via {@link inferenceProfile.parse};
64
+ * - a provisioned-model ARN → `{ modelArn }`.
65
+ *
66
+ * A two-segment id with an unknown first segment throws rather than being
67
+ * taken for a model named after a geography. A system-defined or application
68
+ * profile ARN throws too: the model it routes to cannot be read from it, and
69
+ * a grant on the ARN alone would be incomplete. Pass the profile value instead.
70
+ */
71
+ declare function fromId(id: string, options?: InferenceTargetIdOptions): InferenceTarget;
72
+ /**
73
+ * Factories for {@link InferenceTarget} values.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * const ids = ["anthropic.claude-sonnet-5-5", "us.anthropic.claude-haiku-4-5-20251001-v1:0"];
78
+ * createFunctionBuilder().grant(...ids.map((id) => modelGrants.invoke(inferenceTarget.fromId(id))));
79
+ * ```
80
+ */
81
+ export declare const inferenceTarget: {
82
+ /** Resolves a model id, system-defined profile id or provisioned-model ARN. */
83
+ fromId: typeof fromId;
84
+ };
85
+ export {};
48
86
  //# sourceMappingURL=inference-target.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"inference-target.d.ts","sourceRoot":"","sources":["../../src/inference-target.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjF,OAAO,EAAa,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,KAAK,EAAE,2BAA2B,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE5F;;;;GAIG;AACH,MAAM,MAAM,eAAe,GACzB,yBAAyB,GAAG,gBAAgB,GAAG,2BAA2B,GAAG,MAAM,CAAC;AAEtF,gBAAgB;AAChB,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,IAAI,gBAAgB,CAEtF;AAUD,oFAAoF;AACpF,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,CAAC;IAChC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAC/D;AA4BD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,eAAe,EACvB,KAAK,CAAC,EAAE,UAAU,GACjB,mBAAmB,EAAE,CASvB;AA4DD;;;GAGG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,yBAAyB,GAAG,gBAAgB,EACpD,KAAK,EAAE,UAAU,GAAG,SAAS,GAC5B,MAAM,CAKR;AAED;;;;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AE,UAAU,GAAG,MAAM,EAAE,CAEpF;AAED,gBAAgB;AAChB,wBAAgB,OAAO,CAAC,SAAS,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAElE;AAED,kDAAkD;AAClD,MAAM,WAAW,wBAAwB;IACvC,0FAA0F;IAC1F,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7C;AAID;;;;;;;;;;;;;GAaG;AACH,iBAAS,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,wBAA6B,GAAG,eAAe,CA6BnF;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe;IAC1B,+EAA+E;;CAEhF,CAAC"}
@@ -1,5 +1,7 @@
1
- import { Arn, ArnFormat, Aws, Stack } from "aws-cdk-lib";
1
+ import { FoundationModelIdentifier } from "aws-cdk-lib/aws-bedrock";
2
2
  import { Construct } from "constructs";
3
+ import { bedrockArn, environmentOf } from "./arn.js";
4
+ import { assertLiteralId, idPrefix, INFERENCE_PROFILE_GEOGRAPHIES, inferenceProfile, } from "./inference-profile.js";
3
5
  /** @internal */
4
6
  export function isInferenceProfile(target) {
5
7
  return "kind" in target && (target.kind === "geographic" || target.kind === "global");
@@ -10,26 +12,12 @@ function isApplicationProfile(target) {
10
12
  function isModel(target) {
11
13
  return "modelArn" in target;
12
14
  }
13
- function environmentOf(scope) {
14
- return scope === undefined
15
- ? { partition: Aws.PARTITION, region: Aws.REGION, account: Aws.ACCOUNT_ID }
16
- : Stack.of(scope);
17
- }
18
- function bedrockArn(partition, resource, resourceName, region, account = "") {
19
- return Arn.format({
20
- partition,
21
- service: "bedrock",
22
- region,
23
- account,
24
- resource,
25
- resourceName,
26
- arnFormat: ArnFormat.SLASH_RESOURCE_NAME,
27
- });
28
- }
29
15
  /**
30
16
  * The statements for invoking `target` from the Region `scope` deploys to:
31
17
  * those the Bedrock user guide prescribes, and for an application profile the
32
- * shape verified against live IAM.
18
+ * shape verified against live IAM. A geographic profile without
19
+ * `routingRegions` grants the model in every Region rather than an
20
+ * enumerated list, still only through the profile (#628).
33
21
  *
34
22
  * @see https://docs.aws.amazon.com/bedrock/latest/userguide/geographic-cross-region-inference.html#geographic-cris-iam-setup
35
23
  * @see https://docs.aws.amazon.com/bedrock/latest/userguide/global-cross-region-inference.html#global-cris-iam-setup
@@ -76,7 +64,9 @@ function sourceStatements(target, scope, viaProfile) {
76
64
  const models = target.kind === "geographic"
77
65
  ? [
78
66
  {
79
- resourceArns: [...new Set([sourceRegion, ...target.routingRegions])].map((region) => modelArn(modelId, region)),
67
+ resourceArns: (target.routingRegions
68
+ ? [...new Set([sourceRegion, ...target.routingRegions])]
69
+ : ["*"]).map((region) => modelArn(modelId, region)),
80
70
  conditions: { StringEquals: via },
81
71
  },
82
72
  ]
@@ -110,7 +100,9 @@ export function sourceArn(source, scope) {
110
100
  *
111
101
  * {@link modelGrants.invoke} applies these with the conditions the Bedrock
112
102
  * user guide prescribes; use this list where you write a policy yourself,
113
- * such as a service control policy.
103
+ * such as a service control policy. A geographic profile without
104
+ * `routingRegions` yields one Region-wildcard model ARN, so list the Regions
105
+ * on the profile when the policy must name each one.
114
106
  *
115
107
  * @param scope - Resolves partition, Region and account from its stack. Omit
116
108
  * for the `AWS::` pseudo-parameters.
@@ -122,4 +114,58 @@ export function invocationArns(target, scope) {
122
114
  export function scopeOf(principal) {
123
115
  return Construct.isConstruct(principal) ? principal : undefined;
124
116
  }
117
+ const PROVISIONED_MODEL_ARN = ":provisioned-model/";
118
+ /**
119
+ * Resolves an id that arrives as a string, such as from configuration, to the
120
+ * target it names:
121
+ *
122
+ * - `anthropic.claude-…` → a `FoundationModelIdentifier`;
123
+ * - `eu.anthropic.claude-…` or `global.anthropic.claude-…` → a system-defined
124
+ * profile, via {@link inferenceProfile.parse};
125
+ * - a provisioned-model ARN → `{ modelArn }`.
126
+ *
127
+ * A two-segment id with an unknown first segment throws rather than being
128
+ * taken for a model named after a geography. A system-defined or application
129
+ * profile ARN throws too: the model it routes to cannot be read from it, and
130
+ * a grant on the ARN alone would be incomplete. Pass the profile value instead.
131
+ */
132
+ function fromId(id, options = {}) {
133
+ assertLiteralId(id, "Inference target id");
134
+ if (id.startsWith("arn:")) {
135
+ if (id.includes(PROVISIONED_MODEL_ARN))
136
+ return { modelArn: id };
137
+ throw new Error(`"${id}" is an ARN. inferenceTarget.fromId resolves foundation-model and system-defined ` +
138
+ `profile ids, and provisioned-model ARNs. For an inference profile pass its id, or an ` +
139
+ `ApplicationInferenceProfile value, so the model it routes to is granted as well.`);
140
+ }
141
+ const parsed = idPrefix(id);
142
+ if (!parsed) {
143
+ throw new Error(`"${id}" is not a foundation model or inference profile id.`);
144
+ }
145
+ const { prefix, isProfile } = parsed;
146
+ if (isProfile)
147
+ return inferenceProfile.parse(id, options.routingRegions);
148
+ if (id.includes(".", prefix.length + 1)) {
149
+ throw new Error(`"${id}" looks like an inference profile id, but "${prefix}" is neither global nor one ` +
150
+ `of INFERENCE_PROFILE_GEOGRAPHIES (${INFERENCE_PROFILE_GEOGRAPHIES.join(", ")}). ` +
151
+ `For a new geography use inferenceProfile.geographic().`);
152
+ }
153
+ if (options.routingRegions !== undefined) {
154
+ throw new Error(`"${id}" is a foundation model id; routingRegions apply to a geographic profile.`);
155
+ }
156
+ return new FoundationModelIdentifier(id);
157
+ }
158
+ /**
159
+ * Factories for {@link InferenceTarget} values.
160
+ *
161
+ * @example
162
+ * ```ts
163
+ * const ids = ["anthropic.claude-sonnet-5-5", "us.anthropic.claude-haiku-4-5-20251001-v1:0"];
164
+ * createFunctionBuilder().grant(...ids.map((id) => modelGrants.invoke(inferenceTarget.fromId(id))));
165
+ * ```
166
+ */
167
+ export const inferenceTarget = {
168
+ /** Resolves a model id, system-defined profile id or provisioned-model ARN. */
169
+ fromId,
170
+ };
125
171
  //# sourceMappingURL=inference-target.js.map