@composurecdk/bedrock 0.10.1

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 (69) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +115 -0
  3. package/dist/commonjs/grants.d.ts +27 -0
  4. package/dist/commonjs/grants.d.ts.map +1 -0
  5. package/dist/commonjs/grants.js +42 -0
  6. package/dist/commonjs/grants.js.map +1 -0
  7. package/dist/commonjs/index.d.ts +8 -0
  8. package/dist/commonjs/index.d.ts.map +1 -0
  9. package/dist/commonjs/index.js +18 -0
  10. package/dist/commonjs/index.js.map +1 -0
  11. package/dist/commonjs/inference-profile.d.ts +88 -0
  12. package/dist/commonjs/inference-profile.d.ts.map +1 -0
  13. package/dist/commonjs/inference-profile.js +125 -0
  14. package/dist/commonjs/inference-profile.js.map +1 -0
  15. package/dist/commonjs/inference-target.d.ts +41 -0
  16. package/dist/commonjs/inference-target.d.ts.map +1 -0
  17. package/dist/commonjs/inference-target.js +104 -0
  18. package/dist/commonjs/inference-target.js.map +1 -0
  19. package/dist/commonjs/model-alarm-builder.d.ts +67 -0
  20. package/dist/commonjs/model-alarm-builder.d.ts.map +1 -0
  21. package/dist/commonjs/model-alarm-builder.js +58 -0
  22. package/dist/commonjs/model-alarm-builder.js.map +1 -0
  23. package/dist/commonjs/model-alarm-config.d.ts +83 -0
  24. package/dist/commonjs/model-alarm-config.d.ts.map +1 -0
  25. package/dist/commonjs/model-alarm-config.js +3 -0
  26. package/dist/commonjs/model-alarm-config.js.map +1 -0
  27. package/dist/commonjs/model-alarm-defaults.d.ts +22 -0
  28. package/dist/commonjs/model-alarm-defaults.d.ts.map +1 -0
  29. package/dist/commonjs/model-alarm-defaults.js +30 -0
  30. package/dist/commonjs/model-alarm-defaults.js.map +1 -0
  31. package/dist/commonjs/model-alarms.d.ts +20 -0
  32. package/dist/commonjs/model-alarms.d.ts.map +1 -0
  33. package/dist/commonjs/model-alarms.js +115 -0
  34. package/dist/commonjs/model-alarms.js.map +1 -0
  35. package/dist/commonjs/package.json +3 -0
  36. package/dist/esm/grants.d.ts +27 -0
  37. package/dist/esm/grants.d.ts.map +1 -0
  38. package/dist/esm/grants.js +39 -0
  39. package/dist/esm/grants.js.map +1 -0
  40. package/dist/esm/index.d.ts +8 -0
  41. package/dist/esm/index.d.ts.map +1 -0
  42. package/dist/esm/index.js +7 -0
  43. package/dist/esm/index.js.map +1 -0
  44. package/dist/esm/inference-profile.d.ts +88 -0
  45. package/dist/esm/inference-profile.d.ts.map +1 -0
  46. package/dist/esm/inference-profile.js +121 -0
  47. package/dist/esm/inference-profile.js.map +1 -0
  48. package/dist/esm/inference-target.d.ts +41 -0
  49. package/dist/esm/inference-target.d.ts.map +1 -0
  50. package/dist/esm/inference-target.js +98 -0
  51. package/dist/esm/inference-target.js.map +1 -0
  52. package/dist/esm/model-alarm-builder.d.ts +67 -0
  53. package/dist/esm/model-alarm-builder.d.ts.map +1 -0
  54. package/dist/esm/model-alarm-builder.js +55 -0
  55. package/dist/esm/model-alarm-builder.js.map +1 -0
  56. package/dist/esm/model-alarm-config.d.ts +83 -0
  57. package/dist/esm/model-alarm-config.d.ts.map +1 -0
  58. package/dist/esm/model-alarm-config.js +2 -0
  59. package/dist/esm/model-alarm-config.js.map +1 -0
  60. package/dist/esm/model-alarm-defaults.d.ts +22 -0
  61. package/dist/esm/model-alarm-defaults.d.ts.map +1 -0
  62. package/dist/esm/model-alarm-defaults.js +27 -0
  63. package/dist/esm/model-alarm-defaults.js.map +1 -0
  64. package/dist/esm/model-alarms.d.ts +20 -0
  65. package/dist/esm/model-alarms.d.ts.map +1 -0
  66. package/dist/esm/model-alarms.js +111 -0
  67. package/dist/esm/model-alarms.js.map +1 -0
  68. package/dist/esm/package.json +3 -0
  69. package/package.json +87 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jason Duffett
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # @composurecdk/bedrock
2
+
3
+ Amazon Bedrock model access for [ComposureCDK](../../README.md): references to foundation models and cross-Region inference profiles, the IAM grants to invoke them, and CloudWatch alarms on their metrics.
4
+
5
+ It builds on the stable [`aws-cdk-lib/aws-bedrock`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_bedrock-readme.html) module. Amazon Bedrock AgentCore is a separate service and is not covered here.
6
+
7
+ ```ts
8
+ import { FoundationModelIdentifier } from "aws-cdk-lib/aws-bedrock";
9
+ import { compose } from "@composurecdk/core";
10
+ import { createFunctionBuilder } from "@composurecdk/lambda";
11
+ import { createModelAlarmBuilder, inferenceProfile, modelGrants } from "@composurecdk/bedrock";
12
+
13
+ const haiku = inferenceProfile.geographic({
14
+ model: FoundationModelIdentifier.ANTHROPIC_CLAUDE_HAIKU_4_5_20251001_V1_0,
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
+ });
25
+
26
+ compose(
27
+ {
28
+ handler: createFunctionBuilder()
29
+ // runtime, handler, code …
30
+ .environment({ MODEL_ID: haiku.profileId })
31
+ .grant(modelGrants.invoke(haiku)),
32
+ modelAlarms: createModelAlarmBuilder().model(haiku),
33
+ },
34
+ { handler: [], modelAlarms: [] },
35
+ );
36
+ ```
37
+
38
+ ## Model references
39
+
40
+ `modelGrants` and `createModelAlarmBuilder` take an `InferenceTarget`:
41
+
42
+ | Target | Invokes |
43
+ | ------------------------------------ | ---------------------------------------------------------------------------------- |
44
+ | `FoundationModelIdentifier` | A foundation model in the stack's Region |
45
+ | `inferenceProfile.geographic({ … })` | A cross-Region profile that stays within one geography (`us`, `eu`, `apac`, …) |
46
+ | `inferenceProfile.global(model)` | A cross-Region profile that routes to any supported commercial Region |
47
+ | `IModel` | Any model by ARN, e.g. `ProvisionedModel.fromProvisionedModelArn(…)` (grants only) |
48
+
49
+ 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.
50
+
51
+ `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.
52
+
53
+ For an id that arrives as a string, such as from an environment variable:
54
+
55
+ ```ts
56
+ const profile = inferenceProfile.parse(
57
+ "eu.anthropic.claude-haiku-4-5-20251001-v1:0",
58
+ routingRegions,
59
+ );
60
+ foundationModelFor(profile.profileId).modelId; // "anthropic.claude-haiku-4-5-20251001-v1:0"
61
+ ```
62
+
63
+ `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.
64
+
65
+ ## Grants
66
+
67
+ `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(...)`.
68
+
69
+ | Target | Statements |
70
+ | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
71
+ | Model | The foundation model in the source Region |
72
+ | Geographic | The profile; the foundation model in the source Region and every routing Region, conditioned on `bedrock:InferenceProfileArn` |
73
+ | 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` |
74
+
75
+ These 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.
76
+
77
+ `invocationArns(target, scope)` returns the same resource ARNs for policies you write yourself, such as service control policies.
78
+
79
+ ## Alarms
80
+
81
+ `createModelAlarmBuilder()` creates alarms on the `AWS/Bedrock` metrics of one model. Those metrics are per model per account and Region, across every caller, so create one builder per model in each Region that invokes it — not one per caller. For a cross-Region profile the metrics are emitted in the source Region.
82
+
83
+ AWS publishes no recommended alarm thresholds for Bedrock. The [Generative AI Lens](https://docs.aws.amazon.com/wellarchitected/latest/generative-ai-lens/genops02-bp02.html) names the signals to alarm on; the thresholds below are this library's, shaped after AWS's recommended Lambda `Errors` and `Throttles` alarms.
84
+
85
+ | Alarm | Metric (statistic) | Default |
86
+ | ------------------------ | ------------------------------ | -------------------------------------- |
87
+ | `invocationThrottles` | `InvocationThrottles` (Sum) | on, > 0 in 3 of 5 minutes |
88
+ | `invocationServerErrors` | `InvocationServerErrors` (Sum) | on, > 0 in 3 of 5 minutes |
89
+ | `invocationClientErrors` | `InvocationClientErrors` (Sum) | on, > 0 in 3 of 5 minutes |
90
+ | `invocationLatency` | `InvocationLatency` (p90) | opt-in, threshold required |
91
+ | `timeToFirstToken` | `TimeToFirstToken` (p90) | opt-in, threshold required |
92
+ | `estimatedTpmQuotaUsage` | `EstimatedTPMQuotaUsage` (Max) | opt-in, `quota` required; 80% of quota |
93
+
94
+ `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`.
95
+
96
+ ```ts
97
+ createModelAlarmBuilder()
98
+ .model(haiku)
99
+ .recommendedAlarms({
100
+ invocationLatency: { threshold: 10_000 },
101
+ estimatedTpmQuotaUsage: { quota: 400_000 },
102
+ })
103
+ .addAlarm("outputTokens", (a) =>
104
+ a.metric((m) => m.metric("OutputTokenCount", { statistic: "Sum" })).threshold(1_000_000),
105
+ );
106
+ ```
107
+
108
+ No alarm actions are configured; route them with `alarmActionsPolicy`.
109
+
110
+ ## Not yet covered
111
+
112
+ - **Model invocation logging** ([GENSEC01-BP04](https://docs.aws.amazon.com/wellarchitected/latest/generative-ai-lens/gensec01-bp04.html)). An account-wide, per-Region setting with no CloudFormation resource.
113
+ - **Guardrails** ([GENSEC02-BP01](https://docs.aws.amazon.com/wellarchitected/latest/generative-ai-lens/gensec02-bp01.html)).
114
+ - **Application inference profiles**, for cost allocation tags.
115
+ - **Private connectivity** ([GENSEC01-BP02](https://docs.aws.amazon.com/wellarchitected/latest/generative-ai-lens/gensec01-bp02.html)): a `bedrock-runtime` interface endpoint, built with `@composurecdk/ec2`.
@@ -0,0 +1,27 @@
1
+ import { type IGrantable } from "aws-cdk-lib/aws-iam";
2
+ import { type Grant, type Resolvable } from "@composurecdk/core";
3
+ import { type InferenceTarget } from "./inference-target.js";
4
+ /**
5
+ * Consumer-side grant helpers for invoking Amazon Bedrock models. Pass one to
6
+ * a grantee builder's `grant(...)` — e.g.
7
+ * `createFunctionBuilder().grant(modelGrants.invoke(profile))`.
8
+ *
9
+ * A model is not a construct, so there is no native `grant*` method to
10
+ * delegate to; the statements are those the Bedrock user guide prescribes
11
+ * (ADR-0013 addendum).
12
+ */
13
+ export declare const modelGrants: {
14
+ /**
15
+ * Invoke the target through `InvokeModel`, `Converse` or their streaming
16
+ * variants.
17
+ *
18
+ * For a cross-Region profile this also grants the foundation model in the
19
+ * source Region and every Region the profile routes to, conditioned on
20
+ * `bedrock:InferenceProfileArn` so those models are reachable only through
21
+ * the profile.
22
+ *
23
+ * @see https://docs.aws.amazon.com/wellarchitected/latest/generative-ai-lens/gensec01-bp01.html
24
+ */
25
+ invoke: (target: Resolvable<InferenceTarget>) => Grant<IGrantable>;
26
+ };
27
+ //# sourceMappingURL=grants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grants.d.ts","sourceRoot":"","sources":["../../src/grants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,KAAK,KAAK,EAAY,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,KAAK,eAAe,EAAiC,MAAM,uBAAuB,CAAC;AAU5F;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW;IACtB;;;;;;;;;;OAUG;qBACc,UAAU,CAAC,eAAe,CAAC,KAAG,KAAK,CAAC,UAAU,CAAC;CAOjE,CAAC"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.modelGrants = void 0;
4
+ const aws_iam_1 = require("aws-cdk-lib/aws-iam");
5
+ const core_1 = require("@composurecdk/core");
6
+ const inference_target_js_1 = require("./inference-target.js");
7
+ /**
8
+ * Streaming operations (`InvokeModelWithResponseStream`, `ConverseStream`)
9
+ * require both actions.
10
+ *
11
+ * @see https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonbedrock.html
12
+ */
13
+ const INVOKE_ACTIONS = ["bedrock:InvokeModel", "bedrock:InvokeModelWithResponseStream"];
14
+ /**
15
+ * Consumer-side grant helpers for invoking Amazon Bedrock models. Pass one to
16
+ * a grantee builder's `grant(...)` — e.g.
17
+ * `createFunctionBuilder().grant(modelGrants.invoke(profile))`.
18
+ *
19
+ * A model is not a construct, so there is no native `grant*` method to
20
+ * delegate to; the statements are those the Bedrock user guide prescribes
21
+ * (ADR-0013 addendum).
22
+ */
23
+ exports.modelGrants = {
24
+ /**
25
+ * Invoke the target through `InvokeModel`, `Converse` or their streaming
26
+ * variants.
27
+ *
28
+ * For a cross-Region profile this also grants the foundation model in the
29
+ * source Region and every Region the profile routes to, conditioned on
30
+ * `bedrock:InferenceProfileArn` so those models are reachable only through
31
+ * the profile.
32
+ *
33
+ * @see https://docs.aws.amazon.com/wellarchitected/latest/generative-ai-lens/gensec01-bp01.html
34
+ */
35
+ invoke: (target) => (0, core_1.grantVia)(target, (resolved, grantee) => {
36
+ const statements = (0, inference_target_js_1.invocationStatements)(resolved, (0, inference_target_js_1.scopeOf)(grantee.grantPrincipal));
37
+ for (const { resourceArns, conditions } of statements) {
38
+ aws_iam_1.Grant.addToPrincipal({ grantee, actions: INVOKE_ACTIONS, resourceArns, conditions });
39
+ }
40
+ }),
41
+ };
42
+ //# sourceMappingURL=grants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grants.js","sourceRoot":"","sources":["../../src/grants.ts"],"names":[],"mappings":";;;AAAA,iDAAyE;AACzE,6CAA2E;AAC3E,+DAA4F;AAE5F;;;;;GAKG;AACH,MAAM,cAAc,GAAG,CAAC,qBAAqB,EAAE,uCAAuC,CAAC,CAAC;AAExF;;;;;;;;GAQG;AACU,QAAA,WAAW,GAAG;IACzB;;;;;;;;;;OAUG;IACH,MAAM,EAAE,CAAC,MAAmC,EAAqB,EAAE,CACjE,IAAA,eAAQ,EAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,OAAmB,EAAE,EAAE;QACjD,MAAM,UAAU,GAAG,IAAA,0CAAoB,EAAC,QAAQ,EAAE,IAAA,6BAAO,EAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC;QACnF,KAAK,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,IAAI,UAAU,EAAE,CAAC;YACtD,eAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC,CAAC;QAC1F,CAAC;IACH,CAAC,CAAC;CACL,CAAC"}
@@ -0,0 +1,8 @@
1
+ export { foundationModelFor, type GeographicInferenceProfile, type GeographicInferenceProfileOptions, type GlobalInferenceProfile, INFERENCE_PROFILE_GEOGRAPHIES, type InferenceProfile, type InferenceProfileGeography, inferenceProfile, } from "./inference-profile.js";
2
+ export { type InferenceTarget, invocationArns } from "./inference-target.js";
3
+ export { modelGrants } from "./grants.js";
4
+ export { createModelAlarmBuilder, type IModelAlarmBuilder, type ModelAlarmBuilderProps, type ModelAlarmBuilderResult, } from "./model-alarm-builder.js";
5
+ export { type ModelAlarmConfig, type QuotaAlarmConfig } from "./model-alarm-config.js";
6
+ export { MODEL_ALARM_DEFAULTS } from "./model-alarm-defaults.js";
7
+ export { type ModelAlarmTarget, type ModelMetrics, modelMetrics } from "./model-alarms.js";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,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,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,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"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.modelMetrics = exports.MODEL_ALARM_DEFAULTS = exports.createModelAlarmBuilder = exports.modelGrants = exports.invocationArns = exports.inferenceProfile = exports.INFERENCE_PROFILE_GEOGRAPHIES = exports.foundationModelFor = void 0;
4
+ var inference_profile_js_1 = require("./inference-profile.js");
5
+ Object.defineProperty(exports, "foundationModelFor", { enumerable: true, get: function () { return inference_profile_js_1.foundationModelFor; } });
6
+ Object.defineProperty(exports, "INFERENCE_PROFILE_GEOGRAPHIES", { enumerable: true, get: function () { return inference_profile_js_1.INFERENCE_PROFILE_GEOGRAPHIES; } });
7
+ Object.defineProperty(exports, "inferenceProfile", { enumerable: true, get: function () { return inference_profile_js_1.inferenceProfile; } });
8
+ var inference_target_js_1 = require("./inference-target.js");
9
+ Object.defineProperty(exports, "invocationArns", { enumerable: true, get: function () { return inference_target_js_1.invocationArns; } });
10
+ var grants_js_1 = require("./grants.js");
11
+ Object.defineProperty(exports, "modelGrants", { enumerable: true, get: function () { return grants_js_1.modelGrants; } });
12
+ var model_alarm_builder_js_1 = require("./model-alarm-builder.js");
13
+ Object.defineProperty(exports, "createModelAlarmBuilder", { enumerable: true, get: function () { return model_alarm_builder_js_1.createModelAlarmBuilder; } });
14
+ var model_alarm_defaults_js_1 = require("./model-alarm-defaults.js");
15
+ Object.defineProperty(exports, "MODEL_ALARM_DEFAULTS", { enumerable: true, get: function () { return model_alarm_defaults_js_1.MODEL_ALARM_DEFAULTS; } });
16
+ var model_alarms_js_1 = require("./model-alarms.js");
17
+ Object.defineProperty(exports, "modelMetrics", { enumerable: true, get: function () { return model_alarms_js_1.modelMetrics; } });
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,+DASgC;AAR9B,0HAAA,kBAAkB,OAAA;AAIlB,qIAAA,6BAA6B,OAAA;AAG7B,wHAAA,gBAAgB,OAAA;AAElB,6DAA6E;AAA9C,qHAAA,cAAc,OAAA;AAC7C,yCAA0C;AAAjC,wGAAA,WAAW,OAAA;AACpB,mEAKkC;AAJhC,iIAAA,uBAAuB,OAAA;AAMzB,qEAAiE;AAAxD,+HAAA,oBAAoB,OAAA;AAC7B,qDAA2F;AAAxC,+GAAA,YAAY,OAAA"}
@@ -0,0 +1,88 @@
1
+ import { FoundationModelIdentifier } from "aws-cdk-lib/aws-bedrock";
2
+ /**
3
+ * Geography prefixes of Amazon Bedrock's system-defined cross-Region inference
4
+ * profiles, e.g. the `eu` in `eu.anthropic.claude-haiku-4-5-20251001-v1:0`.
5
+ *
6
+ * {@link inferenceProfile.parse} recognises a profile id by one of these
7
+ * prefixes. {@link inferenceProfile.geographic} also accepts a geography not
8
+ * yet listed here.
9
+ *
10
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/geographic-cross-region-inference.html
11
+ */
12
+ export declare const INFERENCE_PROFILE_GEOGRAPHIES: readonly ["us", "eu", "apac", "jp", "au", "us-gov"];
13
+ /** A known geography prefix. See {@link INFERENCE_PROFILE_GEOGRAPHIES}. */
14
+ export type InferenceProfileGeography = (typeof INFERENCE_PROFILE_GEOGRAPHIES)[number];
15
+ /**
16
+ * A system-defined inference profile that routes requests to Regions within
17
+ * one geography.
18
+ *
19
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/geographic-cross-region-inference.html
20
+ */
21
+ export interface GeographicInferenceProfile {
22
+ readonly kind: "geographic";
23
+ readonly geography: InferenceProfileGeography | (string & {});
24
+ /** The foundation model the profile serves. */
25
+ readonly model: FoundationModelIdentifier;
26
+ /** The id to invoke, e.g. `eu.anthropic.claude-haiku-4-5-20251001-v1:0`. */
27
+ readonly profileId: string;
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.
32
+ */
33
+ readonly routingRegions: readonly string[];
34
+ }
35
+ /**
36
+ * A system-defined inference profile that routes requests to any supported
37
+ * commercial Region.
38
+ *
39
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/global-cross-region-inference.html
40
+ */
41
+ export interface GlobalInferenceProfile {
42
+ readonly kind: "global";
43
+ /** The foundation model the profile serves. */
44
+ readonly model: FoundationModelIdentifier;
45
+ /** The id to invoke, e.g. `global.anthropic.claude-haiku-4-5-20251001-v1:0`. */
46
+ readonly profileId: string;
47
+ }
48
+ /** A system-defined cross-Region inference profile. */
49
+ export type InferenceProfile = GeographicInferenceProfile | GlobalInferenceProfile;
50
+ /** Options for {@link inferenceProfile.geographic}. */
51
+ export type GeographicInferenceProfileOptions = Pick<GeographicInferenceProfile, "model" | "geography" | "routingRegions">;
52
+ declare function geographic(options: GeographicInferenceProfileOptions): GeographicInferenceProfile;
53
+ declare function global(model: FoundationModelIdentifier): GlobalInferenceProfile;
54
+ declare function parse(profileId: string): GlobalInferenceProfile;
55
+ declare function parse(profileId: string, routingRegions: readonly string[]): InferenceProfile;
56
+ /**
57
+ * Factories for {@link InferenceProfile} values.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * const haiku = inferenceProfile.geographic({
62
+ * model: FoundationModelIdentifier.ANTHROPIC_CLAUDE_HAIKU_4_5_20251001_V1_0,
63
+ * geography: "eu",
64
+ * routingRegions: ["eu-central-1", "eu-north-1", "eu-south-1", "eu-south-2", "eu-west-1", "eu-west-3"],
65
+ * });
66
+ * haiku.profileId; // "eu.anthropic.claude-haiku-4-5-20251001-v1:0"
67
+ * ```
68
+ */
69
+ export declare const inferenceProfile: {
70
+ /** A profile routing within one geography. */
71
+ geographic: typeof geographic;
72
+ /** A profile routing to any supported commercial Region. */
73
+ global: typeof global;
74
+ /**
75
+ * Reads a profile id such as `eu.anthropic.claude-haiku-4-5-20251001-v1:0`.
76
+ * Throws unless the id starts with a known geography or `global`. A
77
+ * geographic id needs its `routingRegions`; a global id takes none.
78
+ */
79
+ parse: typeof parse;
80
+ };
81
+ /**
82
+ * The foundation model a system-defined inference profile serves:
83
+ * `eu.anthropic.x` → `anthropic.x`. Throws unless the id starts with a known
84
+ * geography or `global`.
85
+ */
86
+ export declare function foundationModelFor(profileId: string): FoundationModelIdentifier;
87
+ export {};
88
+ //# sourceMappingURL=inference-profile.d.ts.map
@@ -0,0 +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,uDAAuD;AACvD,MAAM,MAAM,iCAAiC,GAAG,IAAI,CAClD,0BAA0B,EAC1B,OAAO,GAAG,WAAW,GAAG,gBAAgB,CACzC,CAAC;AA4CF,iBAAS,UAAU,CAAC,OAAO,EAAE,iCAAiC,GAAG,0BAA0B,CAiB1F;AAED,iBAAS,MAAM,CAAC,KAAK,EAAE,yBAAyB,GAAG,sBAAsB,CAGxE;AAaD,iBAAS,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,sBAAsB,CAAC;AAC1D,iBAAS,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,SAAS,MAAM,EAAE,GAAG,gBAAgB,CAAC;AAkBvF;;;;;;;;;;;;GAYG;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"}
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.inferenceProfile = exports.INFERENCE_PROFILE_GEOGRAPHIES = void 0;
4
+ exports.foundationModelFor = foundationModelFor;
5
+ const aws_cdk_lib_1 = require("aws-cdk-lib");
6
+ const aws_bedrock_1 = require("aws-cdk-lib/aws-bedrock");
7
+ /**
8
+ * Geography prefixes of Amazon Bedrock's system-defined cross-Region inference
9
+ * profiles, e.g. the `eu` in `eu.anthropic.claude-haiku-4-5-20251001-v1:0`.
10
+ *
11
+ * {@link inferenceProfile.parse} recognises a profile id by one of these
12
+ * prefixes. {@link inferenceProfile.geographic} also accepts a geography not
13
+ * yet listed here.
14
+ *
15
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/geographic-cross-region-inference.html
16
+ */
17
+ exports.INFERENCE_PROFILE_GEOGRAPHIES = ["us", "eu", "apac", "jp", "au", "us-gov"];
18
+ const GLOBAL_PREFIX = "global";
19
+ const GEOGRAPHY_PATTERN = /^[a-z]+(-[a-z]+)*$/;
20
+ const REGION_PATTERN = /^[a-z]{2}(-[a-z]+)+-\d+$/;
21
+ function isProfilePrefix(prefix) {
22
+ return (prefix === GLOBAL_PREFIX ||
23
+ exports.INFERENCE_PROFILE_GEOGRAPHIES.includes(prefix));
24
+ }
25
+ function prefixOf(id) {
26
+ const dot = id.indexOf(".");
27
+ return dot > 0 ? id.slice(0, dot) : undefined;
28
+ }
29
+ function assertModel(model) {
30
+ const { modelId } = model;
31
+ if (aws_cdk_lib_1.Token.isUnresolved(modelId) || modelId === "") {
32
+ throw new Error("Inference profile model id must be a non-empty literal string.");
33
+ }
34
+ const prefix = prefixOf(modelId);
35
+ if (prefix !== undefined && isProfilePrefix(prefix)) {
36
+ throw new Error(`"${modelId}" is an inference profile id, not a foundation model id. ` +
37
+ `Use inferenceProfile.parse("${modelId}", …) instead.`);
38
+ }
39
+ }
40
+ function assertRoutingRegions(profileId, regions) {
41
+ if (regions.length === 0) {
42
+ throw new Error(`Inference profile "${profileId}": routingRegions must not be empty.`);
43
+ }
44
+ for (const region of regions) {
45
+ if (aws_cdk_lib_1.Token.isUnresolved(region) || !REGION_PATTERN.test(region)) {
46
+ throw new Error(`Inference profile "${profileId}": "${region}" is not a literal AWS Region code.`);
47
+ }
48
+ }
49
+ }
50
+ function geographic(options) {
51
+ const { model, geography } = options;
52
+ assertModel(model);
53
+ if (geography === GLOBAL_PREFIX || !GEOGRAPHY_PATTERN.test(geography)) {
54
+ throw new Error(`"${geography}" is not a geography prefix. Use inferenceProfile.global() for a global profile.`);
55
+ }
56
+ const profileId = `${geography}.${model.modelId}`;
57
+ assertRoutingRegions(profileId, options.routingRegions);
58
+ return Object.freeze({
59
+ kind: "geographic",
60
+ geography,
61
+ model,
62
+ profileId,
63
+ routingRegions: Object.freeze([...new Set(options.routingRegions)]),
64
+ });
65
+ }
66
+ function global(model) {
67
+ assertModel(model);
68
+ return Object.freeze({ kind: "global", model, profileId: `${GLOBAL_PREFIX}.${model.modelId}` });
69
+ }
70
+ function splitProfileId(profileId) {
71
+ const prefix = prefixOf(profileId);
72
+ if (prefix === undefined || !isProfilePrefix(prefix)) {
73
+ throw new Error(`"${profileId}" is not a system-defined inference profile id. Expected one of the ` +
74
+ `prefixes: ${[GLOBAL_PREFIX, ...exports.INFERENCE_PROFILE_GEOGRAPHIES].join(", ")}.`);
75
+ }
76
+ return { prefix, modelId: profileId.slice(prefix.length + 1) };
77
+ }
78
+ function parse(profileId, routingRegions) {
79
+ const { prefix, modelId } = splitProfileId(profileId);
80
+ const model = new aws_bedrock_1.FoundationModelIdentifier(modelId);
81
+ if (prefix === GLOBAL_PREFIX) {
82
+ if (routingRegions !== undefined) {
83
+ throw new Error(`Inference profile "${profileId}" is global and routes to every supported Region; omit routingRegions.`);
84
+ }
85
+ return global(model);
86
+ }
87
+ if (routingRegions === undefined) {
88
+ throw new Error(`Inference profile "${profileId}" is geographic and needs its routingRegions.`);
89
+ }
90
+ return geographic({ model, geography: prefix, routingRegions });
91
+ }
92
+ /**
93
+ * Factories for {@link InferenceProfile} values.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * const haiku = inferenceProfile.geographic({
98
+ * model: FoundationModelIdentifier.ANTHROPIC_CLAUDE_HAIKU_4_5_20251001_V1_0,
99
+ * geography: "eu",
100
+ * routingRegions: ["eu-central-1", "eu-north-1", "eu-south-1", "eu-south-2", "eu-west-1", "eu-west-3"],
101
+ * });
102
+ * haiku.profileId; // "eu.anthropic.claude-haiku-4-5-20251001-v1:0"
103
+ * ```
104
+ */
105
+ exports.inferenceProfile = {
106
+ /** A profile routing within one geography. */
107
+ geographic,
108
+ /** A profile routing to any supported commercial Region. */
109
+ global,
110
+ /**
111
+ * Reads a profile id such as `eu.anthropic.claude-haiku-4-5-20251001-v1:0`.
112
+ * Throws unless the id starts with a known geography or `global`. A
113
+ * geographic id needs its `routingRegions`; a global id takes none.
114
+ */
115
+ parse,
116
+ };
117
+ /**
118
+ * The foundation model a system-defined inference profile serves:
119
+ * `eu.anthropic.x` → `anthropic.x`. Throws unless the id starts with a known
120
+ * geography or `global`.
121
+ */
122
+ function foundationModelFor(profileId) {
123
+ return new aws_bedrock_1.FoundationModelIdentifier(splitProfileId(profileId).modelId);
124
+ }
125
+ //# sourceMappingURL=inference-profile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inference-profile.js","sourceRoot":"","sources":["../../src/inference-profile.ts"],"names":[],"mappings":";;;AA+LA,gDAEC;AAjMD,6CAAoC;AACpC,yDAAoE;AAEpE;;;;;;;;;GASG;AACU,QAAA,6BAA6B,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAU,CAAC;AAKjG,MAAM,aAAa,GAAG,QAAQ,CAAC;AA8C/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,qCAAmD,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,C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AAC,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,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CAAC,sBAAsB,SAAS,+CAA+C,CAAC,CAAC;IAClG,CAAC;IACD,OAAO,UAAU,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC,CAAC;AAClE,CAAC;AAED;;;;;;;;;;;;GAYG;AACU,QAAA,gBAAgB,GAAG;IAC9B,8CAA8C;IAC9C,UAAU;IACV,4DAA4D;IAC5D,MAAM;IACN;;;;OAIG;IACH,KAAK;CACN,CAAC;AAEF;;;;GAIG;AACH,SAAgB,kBAAkB,CAAC,SAAiB;IAClD,OAAO,IAAI,uCAAyB,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC;AAC1E,CAAC"}
@@ -0,0 +1,41 @@
1
+ import type { FoundationModelIdentifier, IModel } from "aws-cdk-lib/aws-bedrock";
2
+ import { type IConstruct } from "constructs";
3
+ import type { InferenceProfile } from "./inference-profile.js";
4
+ /**
5
+ * Anything a caller can invoke: an in-Region foundation model, a
6
+ * system-defined inference profile, or any {@link IModel} (a provisioned
7
+ * model, or `{ modelArn }` for a model ARN from elsewhere).
8
+ */
9
+ export type InferenceTarget = FoundationModelIdentifier | InferenceProfile | IModel;
10
+ /** @internal */
11
+ export declare function isInferenceProfile(target: InferenceTarget): target is InferenceProfile;
12
+ /** One IAM statement's resources and conditions for invoking a target. @internal */
13
+ export interface InvocationStatement {
14
+ readonly resourceArns: string[];
15
+ readonly conditions?: Record<string, Record<string, unknown>>;
16
+ }
17
+ /**
18
+ * The statements the Bedrock user guide prescribes for invoking `target` from
19
+ * the Region `scope` deploys to.
20
+ *
21
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/geographic-cross-region-inference.html#geographic-cris-iam-setup
22
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/global-cross-region-inference.html#global-cris-iam-setup
23
+ * @internal
24
+ */
25
+ export declare function invocationStatements(target: InferenceTarget, scope?: IConstruct): InvocationStatement[];
26
+ /**
27
+ * Every resource ARN a caller in `scope`'s Region must be allowed to invoke to
28
+ * use `target`. For a cross-Region profile that is the profile plus the
29
+ * foundation model in the source Region and in each Region it routes to.
30
+ *
31
+ * {@link modelGrants.invoke} applies these with the conditions the Bedrock
32
+ * user guide prescribes; use this list where you write a policy yourself,
33
+ * such as a service control policy.
34
+ *
35
+ * @param scope - Resolves partition, Region and account from its stack. Omit
36
+ * for the `AWS::` pseudo-parameters.
37
+ */
38
+ export declare function invocationArns(target: InferenceTarget, scope?: IConstruct): string[];
39
+ /** @internal */
40
+ export declare function scopeOf(principal: unknown): IConstruct | undefined;
41
+ //# sourceMappingURL=inference-target.d.ts.map
@@ -0,0 +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,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,yBAAyB,GAAG,gBAAgB,GAAG,MAAM,CAAC;AAEpF,gBAAgB;AAChB,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,IAAI,gBAAgB,CAEtF;AAMD,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;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,eAAe,EACvB,KAAK,CAAC,EAAE,UAAU,GACjB,mBAAmB,EAAE,CAuDvB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,CAAC,EAAE,UAAU,GAAG,MAAM,EAAE,CAEpF;AAED,gBAAgB;AAChB,wBAAgB,OAAO,CAAC,SAAS,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAElE"}
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isInferenceProfile = isInferenceProfile;
4
+ exports.invocationStatements = invocationStatements;
5
+ exports.invocationArns = invocationArns;
6
+ exports.scopeOf = scopeOf;
7
+ const aws_cdk_lib_1 = require("aws-cdk-lib");
8
+ const constructs_1 = require("constructs");
9
+ /** @internal */
10
+ function isInferenceProfile(target) {
11
+ return "kind" in target;
12
+ }
13
+ function isModel(target) {
14
+ return "modelArn" in target;
15
+ }
16
+ function environmentOf(scope) {
17
+ return scope === undefined
18
+ ? { partition: aws_cdk_lib_1.Aws.PARTITION, region: aws_cdk_lib_1.Aws.REGION, account: aws_cdk_lib_1.Aws.ACCOUNT_ID }
19
+ : aws_cdk_lib_1.Stack.of(scope);
20
+ }
21
+ function bedrockArn(partition, resource, resourceName, region, account = "") {
22
+ return aws_cdk_lib_1.Arn.format({
23
+ partition,
24
+ service: "bedrock",
25
+ region,
26
+ account,
27
+ resource,
28
+ resourceName,
29
+ arnFormat: aws_cdk_lib_1.ArnFormat.SLASH_RESOURCE_NAME,
30
+ });
31
+ }
32
+ /**
33
+ * The statements the Bedrock user guide prescribes for invoking `target` from
34
+ * the Region `scope` deploys to.
35
+ *
36
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/geographic-cross-region-inference.html#geographic-cris-iam-setup
37
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/global-cross-region-inference.html#global-cris-iam-setup
38
+ * @internal
39
+ */
40
+ function invocationStatements(target, scope) {
41
+ if (isModel(target))
42
+ return [{ resourceArns: [target.modelArn] }];
43
+ const { partition, region: sourceRegion, account } = environmentOf(scope);
44
+ const modelArn = (modelId, region) => bedrockArn(partition, "foundation-model", modelId, region);
45
+ if (!isInferenceProfile(target)) {
46
+ return [{ resourceArns: [modelArn(target.modelId, sourceRegion)] }];
47
+ }
48
+ const profileArn = bedrockArn(partition, "inference-profile", target.profileId, sourceRegion, account);
49
+ const { modelId } = target.model;
50
+ if (target.kind === "geographic") {
51
+ const regions = [...new Set([sourceRegion, ...target.routingRegions])];
52
+ return [
53
+ { resourceArns: [profileArn] },
54
+ {
55
+ resourceArns: regions.map((region) => modelArn(modelId, region)),
56
+ conditions: { StringEquals: { "bedrock:InferenceProfileArn": profileArn } },
57
+ },
58
+ ];
59
+ }
60
+ return [
61
+ {
62
+ resourceArns: [profileArn],
63
+ conditions: { StringEquals: { "aws:RequestedRegion": sourceRegion } },
64
+ },
65
+ {
66
+ resourceArns: [modelArn(modelId, sourceRegion)],
67
+ conditions: {
68
+ StringEquals: {
69
+ "aws:RequestedRegion": sourceRegion,
70
+ "bedrock:InferenceProfileArn": profileArn,
71
+ },
72
+ },
73
+ },
74
+ {
75
+ resourceArns: [modelArn(modelId, "")],
76
+ conditions: {
77
+ StringEquals: {
78
+ "aws:RequestedRegion": "unspecified",
79
+ "bedrock:InferenceProfileArn": profileArn,
80
+ },
81
+ },
82
+ },
83
+ ];
84
+ }
85
+ /**
86
+ * Every resource ARN a caller in `scope`'s Region must be allowed to invoke to
87
+ * use `target`. For a cross-Region profile that is the profile plus the
88
+ * foundation model in the source Region and in each Region it routes to.
89
+ *
90
+ * {@link modelGrants.invoke} applies these with the conditions the Bedrock
91
+ * user guide prescribes; use this list where you write a policy yourself,
92
+ * such as a service control policy.
93
+ *
94
+ * @param scope - Resolves partition, Region and account from its stack. Omit
95
+ * for the `AWS::` pseudo-parameters.
96
+ */
97
+ function invocationArns(target, scope) {
98
+ return invocationStatements(target, scope).flatMap((s) => s.resourceArns);
99
+ }
100
+ /** @internal */
101
+ function scopeOf(principal) {
102
+ return constructs_1.Construct.isConstruct(principal) ? principal : undefined;
103
+ }
104
+ //# sourceMappingURL=inference-target.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inference-target.js","sourceRoot":"","sources":["../../src/inference-target.ts"],"names":[],"mappings":";;AAaA,gDAEC;AA8CD,oDA0DC;AAcD,wCAEC;AAGD,0BAEC;AA5ID,6CAAyD;AAEzD,2CAAwD;AAUxD,gBAAgB;AAChB,SAAgB,kBAAkB,CAAC,MAAuB;IACxD,OAAO,MAAM,IAAI,MAAM,CAAC;AAC1B,CAAC;AAED,SAAS,OAAO,CAAC,MAAuB;IACtC,OAAO,UAAU,IAAI,MAAM,CAAC;AAC9B,CAAC;AAUD,SAAS,aAAa,CAAC,KAA6B;IAClD,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,SAAS,UAAU,CACjB,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;AAED;;;;;;;GAOG;AACH,SAAgB,oBA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