@composurecdk/bedrock 0.10.1 → 0.10.3

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 (102) hide show
  1. package/README.md +110 -17
  2. package/dist/commonjs/alarm-definition.d.ts +29 -0
  3. package/dist/commonjs/alarm-definition.d.ts.map +1 -0
  4. package/dist/commonjs/alarm-definition.js +53 -0
  5. package/dist/commonjs/alarm-definition.js.map +1 -0
  6. package/dist/commonjs/application-inference-profile-builder.d.ts +44 -0
  7. package/dist/commonjs/application-inference-profile-builder.d.ts.map +1 -0
  8. package/dist/commonjs/application-inference-profile-builder.js +51 -0
  9. package/dist/commonjs/application-inference-profile-builder.js.map +1 -0
  10. package/dist/commonjs/grants.d.ts +25 -1
  11. package/dist/commonjs/grants.d.ts.map +1 -1
  12. package/dist/commonjs/grants.js +57 -6
  13. package/dist/commonjs/grants.js.map +1 -1
  14. package/dist/commonjs/guardrail-alarms.d.ts +40 -0
  15. package/dist/commonjs/guardrail-alarms.d.ts.map +1 -0
  16. package/dist/commonjs/guardrail-alarms.js +41 -0
  17. package/dist/commonjs/guardrail-alarms.js.map +1 -0
  18. package/dist/commonjs/guardrail-builder.d.ts +70 -0
  19. package/dist/commonjs/guardrail-builder.d.ts.map +1 -0
  20. package/dist/commonjs/guardrail-builder.js +78 -0
  21. package/dist/commonjs/guardrail-builder.js.map +1 -0
  22. package/dist/commonjs/guardrail-defaults.d.ts +25 -0
  23. package/dist/commonjs/guardrail-defaults.d.ts.map +1 -0
  24. package/dist/commonjs/guardrail-defaults.js +30 -0
  25. package/dist/commonjs/guardrail-defaults.js.map +1 -0
  26. package/dist/commonjs/index.d.ts +8 -2
  27. package/dist/commonjs/index.d.ts.map +1 -1
  28. package/dist/commonjs/index.js +15 -1
  29. package/dist/commonjs/index.js.map +1 -1
  30. package/dist/commonjs/inference-profile.d.ts +19 -0
  31. package/dist/commonjs/inference-profile.d.ts.map +1 -1
  32. package/dist/commonjs/inference-profile.js.map +1 -1
  33. package/dist/commonjs/inference-target.d.ts +14 -7
  34. package/dist/commonjs/inference-target.d.ts.map +1 -1
  35. package/dist/commonjs/inference-target.js +63 -35
  36. package/dist/commonjs/inference-target.js.map +1 -1
  37. package/dist/commonjs/model-alarm-defaults.d.ts.map +1 -1
  38. package/dist/commonjs/model-alarm-defaults.js +5 -14
  39. package/dist/commonjs/model-alarm-defaults.js.map +1 -1
  40. package/dist/commonjs/model-alarms.d.ts +2 -2
  41. package/dist/commonjs/model-alarms.d.ts.map +1 -1
  42. package/dist/commonjs/model-alarms.js +35 -58
  43. package/dist/commonjs/model-alarms.js.map +1 -1
  44. package/dist/commonjs/model-invocation-logging-alarms.d.ts +42 -0
  45. package/dist/commonjs/model-invocation-logging-alarms.d.ts.map +1 -0
  46. package/dist/commonjs/model-invocation-logging-alarms.js +59 -0
  47. package/dist/commonjs/model-invocation-logging-alarms.js.map +1 -0
  48. package/dist/commonjs/model-invocation-logging-builder.d.ts +84 -0
  49. package/dist/commonjs/model-invocation-logging-builder.d.ts.map +1 -0
  50. package/dist/commonjs/model-invocation-logging-builder.js +135 -0
  51. package/dist/commonjs/model-invocation-logging-builder.js.map +1 -0
  52. package/dist/esm/alarm-definition.d.ts +29 -0
  53. package/dist/esm/alarm-definition.d.ts.map +1 -0
  54. package/dist/esm/alarm-definition.js +48 -0
  55. package/dist/esm/alarm-definition.js.map +1 -0
  56. package/dist/esm/application-inference-profile-builder.d.ts +44 -0
  57. package/dist/esm/application-inference-profile-builder.d.ts.map +1 -0
  58. package/dist/esm/application-inference-profile-builder.js +48 -0
  59. package/dist/esm/application-inference-profile-builder.js.map +1 -0
  60. package/dist/esm/grants.d.ts +25 -1
  61. package/dist/esm/grants.d.ts.map +1 -1
  62. package/dist/esm/grants.js +58 -7
  63. package/dist/esm/grants.js.map +1 -1
  64. package/dist/esm/guardrail-alarms.d.ts +40 -0
  65. package/dist/esm/guardrail-alarms.d.ts.map +1 -0
  66. package/dist/esm/guardrail-alarms.js +37 -0
  67. package/dist/esm/guardrail-alarms.js.map +1 -0
  68. package/dist/esm/guardrail-builder.d.ts +70 -0
  69. package/dist/esm/guardrail-builder.d.ts.map +1 -0
  70. package/dist/esm/guardrail-builder.js +75 -0
  71. package/dist/esm/guardrail-builder.js.map +1 -0
  72. package/dist/esm/guardrail-defaults.d.ts +25 -0
  73. package/dist/esm/guardrail-defaults.d.ts.map +1 -0
  74. package/dist/esm/guardrail-defaults.js +27 -0
  75. package/dist/esm/guardrail-defaults.js.map +1 -0
  76. package/dist/esm/index.d.ts +8 -2
  77. package/dist/esm/index.d.ts.map +1 -1
  78. package/dist/esm/index.js +7 -1
  79. package/dist/esm/index.js.map +1 -1
  80. package/dist/esm/inference-profile.d.ts +19 -0
  81. package/dist/esm/inference-profile.d.ts.map +1 -1
  82. package/dist/esm/inference-profile.js.map +1 -1
  83. package/dist/esm/inference-target.d.ts +14 -7
  84. package/dist/esm/inference-target.d.ts.map +1 -1
  85. package/dist/esm/inference-target.js +62 -35
  86. package/dist/esm/inference-target.js.map +1 -1
  87. package/dist/esm/model-alarm-defaults.d.ts.map +1 -1
  88. package/dist/esm/model-alarm-defaults.js +1 -10
  89. package/dist/esm/model-alarm-defaults.js.map +1 -1
  90. package/dist/esm/model-alarms.d.ts +2 -2
  91. package/dist/esm/model-alarms.d.ts.map +1 -1
  92. package/dist/esm/model-alarms.js +35 -58
  93. package/dist/esm/model-alarms.js.map +1 -1
  94. package/dist/esm/model-invocation-logging-alarms.d.ts +42 -0
  95. package/dist/esm/model-invocation-logging-alarms.d.ts.map +1 -0
  96. package/dist/esm/model-invocation-logging-alarms.js +55 -0
  97. package/dist/esm/model-invocation-logging-alarms.js.map +1 -0
  98. package/dist/esm/model-invocation-logging-builder.d.ts +84 -0
  99. package/dist/esm/model-invocation-logging-builder.d.ts.map +1 -0
  100. package/dist/esm/model-invocation-logging-builder.js +131 -0
  101. package/dist/esm/model-invocation-logging-builder.js.map +1 -0
  102. package/package.json +5 -11
package/README.md CHANGED
@@ -39,12 +39,13 @@ compose(
39
39
 
40
40
  `modelGrants` and `createModelAlarmBuilder` take an `InferenceTarget`:
41
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) |
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
+ | `ApplicationInferenceProfile` | An account-owned profile over a model or system-defined profile, tagged for cost allocation |
48
+ | `IModel` | Any model by ARN, e.g. `ProvisionedModel.fromProvisionedModelArn(…)` (grants only) |
48
49
 
49
50
  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
 
@@ -62,17 +63,20 @@ foundationModelFor(profile.profileId).modelId; // "anthropic.claude-haiku-4-5-20
62
63
 
63
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.
64
65
 
66
+ 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
+
65
68
  ## Grants
66
69
 
67
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(...)`.
68
71
 
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` |
72
+ | Target | Statements |
73
+ | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
74
+ | 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` |
76
+ | 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
+ | Application | The profile; its source's foundation models, conditioned on `bedrock:InferenceProfileArn` being the application profile |
74
78
 
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.
79
+ 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.
76
80
 
77
81
  `invocationArns(target, scope)` returns the same resource ARNs for policies you write yourself, such as service control policies.
78
82
 
@@ -107,9 +111,98 @@ createModelAlarmBuilder()
107
111
 
108
112
  No alarm actions are configured; route them with `alarmActionsPolicy`.
109
113
 
110
- ## Not yet covered
114
+ ## Model invocation logging
115
+
116
+ `createModelInvocationLoggingBuilder()` turns on [model invocation logging](https://docs.aws.amazon.com/bedrock/latest/userguide/model-invocation-logging.html) for the account in the stack's Region ([GENSEC01-BP04](https://docs.aws.amazon.com/wellarchitected/latest/generative-ai-lens/gensec01-bp04.html)). The setting has no CloudFormation resource, so a custom resource applies it on deploy and deletes it with the stack.
117
+
118
+ ```ts
119
+ createModelInvocationLoggingBuilder()
120
+ .largeDataBucket(ref("audit", (r: BucketBuilderResult) => r.bucket))
121
+ .largeDataKeyPrefix("bedrock");
122
+ ```
123
+
124
+ It creates:
125
+
126
+ - a log group, from `@composurecdk/logs`' defaults; customise it with `logGroup: { configure }`;
127
+ - a role Bedrock assumes to write to the log group's `aws/bedrock/modelinvocations` stream, trusted only for this account and Region;
128
+ - an alarm on failed deliveries to the log group, and to the large-data bucket when one is configured.
129
+
130
+ Every modality is logged by default (`MODEL_INVOCATION_LOGGING_DEFAULTS`). Bodies over 100 KB and binary data are only logged to a `largeDataBucket`.
131
+
132
+ The setting is one per account and Region. Build it once: a second stack's configuration overwrites the first, and deleting either stack turns logging off.
133
+
134
+ ## Guardrails
135
+
136
+ `createGuardrailBuilder()` creates a guardrail and publishes a version of it ([GENSEC02-BP01](https://docs.aws.amazon.com/wellarchitected/latest/generative-ai-lens/gensec02-bp01.html)). A configuration change publishes a new version, so callers never use the working draft.
137
+
138
+ ```ts
139
+ compose(
140
+ {
141
+ safety: createGuardrailBuilder()
142
+ .name("support-assistant")
143
+ .topicPolicyConfig({
144
+ topicsConfig: [{ name: "Legal", definition: "Legal advice.", type: "DENY" }],
145
+ }),
146
+ handler: createFunctionBuilder()
147
+ // runtime, handler, code …
148
+ .grant(
149
+ modelGrants.invoke(haiku, {
150
+ requireGuardrail: ref("safety", (r: GuardrailBuilderResult) => r.reference),
151
+ }),
152
+ ),
153
+ },
154
+ { safety: [], handler: ["safety"] },
155
+ );
156
+ ```
157
+
158
+ 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
+
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.
161
+
162
+ 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.
111
163
 
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`.
164
+ ### Why the L1 constructs, not the alpha L2
165
+
166
+ The builder wraps `CfnGuardrail` and `CfnGuardrailVersion` because the `Guardrail` L2 is still only in `@aws-cdk/aws-bedrock-alpha`. Building on the alpha would:
167
+
168
+ - make it a peer dependency of this whole package, version-locked to each `aws-cdk-lib` release, even for consumers who only use `modelGrants`;
169
+ - inherit its bug of replacing the guardrail version on every deploy ([aws/aws-cdk#38674](https://github.com/aws/aws-cdk/issues/38674)).
170
+
171
+ When `aws-cdk-lib` ships a stable `Guardrail`, the builder will move onto it ([#533](https://github.com/laazyj/composureCDK/issues/533)). `result.reference` (used by grants and alarms) and `GUARDRAIL_DEFAULTS` carry over; `result.guardrail`, `result.version` and the `CfnGuardrailProps`-shaped props will change to the L2's.
172
+
173
+ ## Application inference profiles
174
+
175
+ `createApplicationInferenceProfileBuilder()` creates an account-owned inference profile over a foundation model or a system-defined profile. The builder's tags land on the profile, so a workload's model usage can be separated in cost allocation.
176
+
177
+ ```ts
178
+ const supportModel = ref<ApplicationInferenceProfileBuilderResult>("supportModel").get("profile");
179
+
180
+ compose(
181
+ {
182
+ supportModel: createApplicationInferenceProfileBuilder()
183
+ .inferenceProfileName("support-assistant")
184
+ .source(haiku)
185
+ .tag("CostCentre", "support"),
186
+ handler: createFunctionBuilder()
187
+ // runtime, handler, code …
188
+ .environment({ MODEL_ID: supportModel.get("profileArn") })
189
+ .grant(modelGrants.invoke(supportModel)),
190
+ },
191
+ { supportModel: [], handler: ["supportModel"] },
192
+ );
193
+ ```
194
+
195
+ Bedrock reports calls through the profile under its own id, not the source model's, so alarm on the profile: `createModelAlarmBuilder().model(supportModel)`.
196
+
197
+ The builder wraps `CfnApplicationInferenceProfile` rather than the alpha `ApplicationInferenceProfile` L2 for the reasons given for [guardrails](#why-the-l1-constructs-not-the-alpha-l2), and because `modelGrants` grants what live IAM needs rather than the alpha's broader grants. It will move onto the L2 when `aws-cdk-lib` ships one ([#534](https://github.com/laazyj/composureCDK/issues/534)); the `ApplicationInferenceProfile` value, grants and alarms carry over.
198
+
199
+ ## Private connectivity
200
+
201
+ To keep model calls off the public internet ([GENSEC01-BP02](https://docs.aws.amazon.com/wellarchitected/latest/generative-ai-lens/gensec01-bp02.html)), give the VPC a `bedrock-runtime` interface endpoint with `@composurecdk/ec2`:
202
+
203
+ ```ts
204
+ createInterfaceEndpointBuilder()
205
+ .vpc(ref<VpcBuilderResult>("network").get("vpc"))
206
+ .service(InterfaceVpcEndpointAwsService.BEDROCK_RUNTIME)
207
+ .allowDefaultPortFrom(ref<FunctionBuilderResult>("handler").get("function"));
208
+ ```
@@ -0,0 +1,29 @@
1
+ import { type Metric, TreatMissingData } from "aws-cdk-lib/aws-cloudwatch";
2
+ import type { AlarmConfig, AlarmConfigDefaults, AlarmDefinition, ResolvedAlarmConfig } from "@composurecdk/cloudwatch";
3
+ /**
4
+ * 3 breaching minutes out of 5: SDK retries absorb isolated throttles and
5
+ * transient errors, so a single datapoint is noise. No traffic emits no data.
6
+ * @internal
7
+ */
8
+ export declare const SUSTAINED: {
9
+ evaluationPeriods: number;
10
+ datapointsToAlarm: number;
11
+ treatMissingData: TreatMissingData;
12
+ };
13
+ /** A greater-than alarm definition from a resolved config. @internal */
14
+ export declare function toDefinition(key: string, metric: Metric, cfg: ResolvedAlarmConfig, description: string): AlarmDefinition;
15
+ /** A recommended alarm on one metric. @internal */
16
+ export interface ThresholdAlarmSpec {
17
+ metricName: string;
18
+ statistic: string;
19
+ /** Absent for opt-in alarms, whose threshold the caller must supply. */
20
+ defaults?: AlarmConfigDefaults;
21
+ describe: (threshold: number) => string;
22
+ }
23
+ /**
24
+ * Resolves each spec against the caller's config: on-by-default alarms merge
25
+ * over their defaults, opt-in alarms are created only when configured, with
26
+ * a threshold. @internal
27
+ */
28
+ export declare function resolveThresholdAlarms<K extends string>(specs: Record<K, ThresholdAlarmSpec>, config: Partial<Record<K, AlarmConfig | false>> | undefined, metric: (metricName: string, statistic: string) => Metric): AlarmDefinition[];
29
+ //# sourceMappingURL=alarm-definition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alarm-definition.d.ts","sourceRoot":"","sources":["../../src/alarm-definition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,MAAM,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC/F,OAAO,KAAK,EACV,WAAW,EACX,mBAAmB,EACnB,eAAe,EACf,mBAAmB,EACpB,MAAM,0BAA0B,CAAC;AAGlC;;;;GAIG;AACH,eAAO,MAAM,SAAS;;;;CAIrB,CAAC;AAEF,wEAAwE;AACxE,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,mBAAmB,EACxB,WAAW,EAAE,MAAM,GAClB,eAAe,CAYjB;AAED,mDAAmD;AACnD,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,wEAAwE;IACxE,QAAQ,CAAC,EAAE,mBAAmB,CAAC;IAC/B,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC;CACzC;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,MAAM,EACrD,KAAK,EAAE,MAAM,CAAC,CAAC,EAAE,kBAAkB,CAAC,EACpC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC,CAAC,GAAG,SAAS,EAC3D,MAAM,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,MAAM,GACxD,eAAe,EAAE,CAgBnB"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SUSTAINED = void 0;
4
+ exports.toDefinition = toDefinition;
5
+ exports.resolveThresholdAlarms = resolveThresholdAlarms;
6
+ const aws_cloudwatch_1 = require("aws-cdk-lib/aws-cloudwatch");
7
+ const cloudwatch_1 = require("@composurecdk/cloudwatch");
8
+ /**
9
+ * 3 breaching minutes out of 5: SDK retries absorb isolated throttles and
10
+ * transient errors, so a single datapoint is noise. No traffic emits no data.
11
+ * @internal
12
+ */
13
+ exports.SUSTAINED = {
14
+ evaluationPeriods: 5,
15
+ datapointsToAlarm: 3,
16
+ treatMissingData: aws_cloudwatch_1.TreatMissingData.NOT_BREACHING,
17
+ };
18
+ /** A greater-than alarm definition from a resolved config. @internal */
19
+ function toDefinition(key, metric, cfg, description) {
20
+ return {
21
+ key,
22
+ alarmName: cfg.alarmName,
23
+ metric,
24
+ threshold: cfg.threshold,
25
+ comparisonOperator: aws_cloudwatch_1.ComparisonOperator.GREATER_THAN_THRESHOLD,
26
+ evaluationPeriods: cfg.evaluationPeriods,
27
+ datapointsToAlarm: cfg.datapointsToAlarm,
28
+ treatMissingData: cfg.treatMissingData,
29
+ description,
30
+ };
31
+ }
32
+ /**
33
+ * Resolves each spec against the caller's config: on-by-default alarms merge
34
+ * over their defaults, opt-in alarms are created only when configured, with
35
+ * a threshold. @internal
36
+ */
37
+ function resolveThresholdAlarms(specs, config, metric) {
38
+ return Object.keys(specs).flatMap((key) => {
39
+ const spec = specs[key];
40
+ const userConfig = config?.[key];
41
+ if (userConfig === false || (userConfig === undefined && !spec.defaults))
42
+ return [];
43
+ if (!spec.defaults && userConfig?.threshold === undefined) {
44
+ throw new Error(`The "${key}" alarm has no default threshold. Supply one, e.g. ` +
45
+ `recommendedAlarms({ ${key}: { threshold: … } }).`);
46
+ }
47
+ const cfg = (0, cloudwatch_1.resolveAlarmConfig)(userConfig, spec.defaults ?? { ...exports.SUSTAINED, threshold: 0 });
48
+ return [
49
+ toDefinition(key, metric(spec.metricName, spec.statistic), cfg, spec.describe(cfg.threshold)),
50
+ ];
51
+ });
52
+ }
53
+ //# sourceMappingURL=alarm-definition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alarm-definition.js","sourceRoot":"","sources":["../../src/alarm-definition.ts"],"names":[],"mappings":";;;AAqBA,oCAiBC;AAgBD,wDAoBC;AA1ED,+DAA+F;AAO/F,yDAA8D;AAE9D;;;;GAIG;AACU,QAAA,SAAS,GAAG;IACvB,iBAAiB,EAAE,CAAC;IACpB,iBAAiB,EAAE,CAAC;IACpB,gBAAgB,EAAE,iCAAgB,CAAC,aAAa;CACjD,CAAC;AAEF,wEAAwE;AACxE,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IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;SAC9F,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { CfnApplicationInferenceProfile, type CfnApplicationInferenceProfileProps } from "aws-cdk-lib/aws-bedrock";
2
+ import type { IConstruct } from "constructs";
3
+ import { type Lifecycle, type Resolvable } from "@composurecdk/core";
4
+ import { type ITaggedBuilder } from "@composurecdk/cloudformation";
5
+ import type { ApplicationInferenceProfile } from "./inference-profile.js";
6
+ /** Configuration properties for {@link createApplicationInferenceProfileBuilder}. */
7
+ export interface ApplicationInferenceProfileBuilderProps extends Omit<CfnApplicationInferenceProfileProps, "modelSource" | "tags"> {
8
+ /** The foundation model or system-defined profile to route to. Required. */
9
+ source: Resolvable<ApplicationInferenceProfile["source"]>;
10
+ }
11
+ /** The build output of an {@link IApplicationInferenceProfileBuilder}. */
12
+ export interface ApplicationInferenceProfileBuilderResult {
13
+ applicationInferenceProfile: CfnApplicationInferenceProfile;
14
+ /** The profile as an invocation target, for grants and callers. */
15
+ profile: ApplicationInferenceProfile;
16
+ }
17
+ /**
18
+ * A fluent builder for an Amazon Bedrock application inference profile.
19
+ *
20
+ * @see {@link createApplicationInferenceProfileBuilder}
21
+ */
22
+ export type IApplicationInferenceProfileBuilder = ITaggedBuilder<ApplicationInferenceProfileBuilderProps, ApplicationInferenceProfileBuilder>;
23
+ declare class ApplicationInferenceProfileBuilder implements Lifecycle<ApplicationInferenceProfileBuilderResult> {
24
+ props: Partial<ApplicationInferenceProfileBuilderProps>;
25
+ build(scope: IConstruct, id: string, context?: Record<string, object>): ApplicationInferenceProfileBuilderResult;
26
+ }
27
+ /**
28
+ * Creates a builder for an {@link ApplicationInferenceProfile}, which carries
29
+ * the builder's tags. Pass the result's `profile` to `modelGrants.invoke`, and
30
+ * its `profileArn` to callers as the model id.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * createApplicationInferenceProfileBuilder()
35
+ * .inferenceProfileName("support-assistant")
36
+ * .source(haiku)
37
+ * .tag("CostCentre", "support");
38
+ * ```
39
+ *
40
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles-create.html
41
+ */
42
+ export declare function createApplicationInferenceProfileBuilder(): IApplicationInferenceProfileBuilder;
43
+ export {};
44
+ //# sourceMappingURL=application-inference-profile-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application-inference-profile-builder.d.ts","sourceRoot":"","sources":["../../src/application-inference-profile-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,KAAK,mCAAmC,EACzC,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,KAAK,SAAS,EAAW,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,KAAK,cAAc,EAAiB,MAAM,8BAA8B,CAAC;AAClF,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAG1E,qFAAqF;AACrF,MAAM,WAAW,uCAAwC,SAAQ,IAAI,CACnE,mCAAmC,EACnC,aAAa,GAAG,MAAM,CACvB;IACC,4EAA4E;IAC5E,MAAM,EAAE,UAAU,CAAC,2BAA2B,CAAC,QAAQ,CAAC,CAAC,CAAC;CAC3D;AAED,0EAA0E;AAC1E,MAAM,WAAW,wCAAwC;IACvD,2BAA2B,EAAE,8BAA8B,CAAC;IAC5D,mEAAmE;IACnE,OAAO,EAAE,2BAA2B,CAAC;CACtC;AAED;;;;GAIG;AACH,MAAM,MAAM,mCAAmC,GAAG,cAAc,CAC9D,uCAAuC,EACvC,kCAAkC,CACnC,CAAC;AAEF,cAAM,kCAAmC,YAAW,SAAS,CAAC,wCAAwC,CAAC;IACrG,KAAK,EAAE,OAAO,CAAC,uCAAuC,CAAC,CAAM;IAE7D,KAAK,CACH,KAAK,EAAE,UAAU,EACjB,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACnC,wCAAwC;CAwB5C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,wCAAwC,IAAI,mCAAmC,CAI9F"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createApplicationInferenceProfileBuilder = createApplicationInferenceProfileBuilder;
4
+ const aws_bedrock_1 = require("aws-cdk-lib/aws-bedrock");
5
+ const core_1 = require("@composurecdk/core");
6
+ const cloudformation_1 = require("@composurecdk/cloudformation");
7
+ const inference_target_js_1 = require("./inference-target.js");
8
+ class ApplicationInferenceProfileBuilder {
9
+ props = {};
10
+ build(scope, id, context = {}) {
11
+ const { source: sourceRef, inferenceProfileName, ...rest } = this.props;
12
+ if (!inferenceProfileName || sourceRef === undefined) {
13
+ throw new Error(`ApplicationInferenceProfileBuilder "${id}" requires an inferenceProfileName and a ` +
14
+ `source. Call .inferenceProfileName() and .source().`);
15
+ }
16
+ const source = (0, core_1.resolve)(sourceRef, context);
17
+ const applicationInferenceProfile = new aws_bedrock_1.CfnApplicationInferenceProfile(scope, id, {
18
+ ...rest,
19
+ inferenceProfileName,
20
+ modelSource: { copyFrom: (0, inference_target_js_1.sourceArn)(source, scope) },
21
+ });
22
+ return {
23
+ applicationInferenceProfile,
24
+ profile: {
25
+ kind: "application",
26
+ profileArn: applicationInferenceProfile.attrInferenceProfileArn,
27
+ profileId: applicationInferenceProfile.attrInferenceProfileId,
28
+ source,
29
+ },
30
+ };
31
+ }
32
+ }
33
+ /**
34
+ * Creates a builder for an {@link ApplicationInferenceProfile}, which carries
35
+ * the builder's tags. Pass the result's `profile` to `modelGrants.invoke`, and
36
+ * its `profileArn` to callers as the model id.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * createApplicationInferenceProfileBuilder()
41
+ * .inferenceProfileName("support-assistant")
42
+ * .source(haiku)
43
+ * .tag("CostCentre", "support");
44
+ * ```
45
+ *
46
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles-create.html
47
+ */
48
+ function createApplicationInferenceProfileBuilder() {
49
+ return (0, cloudformation_1.taggedBuilder)(ApplicationInferenceProfileBuilder);
50
+ }
51
+ //# sourceMappingURL=application-inference-profile-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application-inference-profile-builder.js","sourceRoot":"","sources":["../../src/application-inference-profile-builder.ts"],"names":[],"mappings":";;AAoFA,4FAIC;AAxFD,yDAGiC;AAEjC,6CAA8E;AAC9E,iEAAkF;AAElF,+DAAkD;AA4BlD,MAAM,kCAAkC;IACtC,KAAK,GAAqD,EAAE,CAAC;IAE7D,KAAK,CACH,KAAiB,EACjB,EAAU,EACV,UAAkC,EAAE;QAEpC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,oBAAoB,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QACxE,IAAI,CAAC,oBAAoB,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YACrD,MAAM,IAAI,KAAK,CACb,uCAAuC,EAAE,2CAA2C;gBAClF,qDAAqD,CACxD,CAAC;QACJ,CAAC;QACD,MAAM,MAAM,GAAG,IAAA,cAAO,EAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAC3C,MAAM,2BAA2B,GAAG,IAAI,4CAA8B,CAAC,KAAK,EAAE,EAAE,EAAE;YAChF,GAAG,IAAI;YACP,oBAAoB;YACpB,WAAW,EAAE,EAAE,QAAQ,EAAE,IAAA,+BAAS,EAAC,MAAM,EAAE,KAAK,CAAC,EAAE;SACpD,CAAC,CAAC;QACH,OAAO;YACL,2BAA2B;YAC3B,OAAO,EAAE;gBACP,IAAI,EAAE,aAAa;gBACnB,UAAU,EAAE,2BAA2B,CAAC,uBAAuB;gBAC/D,SAAS,EAAE,2BAA2B,CAAC,sBAAsB;gBAC7D,MAAM;aACP;SACF,CAAC;IACJ,CAAC;CACF;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAgB,wCAAwC;IACtD,OAAO,IAAA,8BAAa,EAClB,kCAAkC,CACnC,CAAC;AACJ,CAAC"}
@@ -1,6 +1,18 @@
1
1
  import { type IGrantable } from "aws-cdk-lib/aws-iam";
2
2
  import { type Grant, type Resolvable } from "@composurecdk/core";
3
+ import type { GuardrailReference } from "./guardrail-builder.js";
3
4
  import { type InferenceTarget } from "./inference-target.js";
5
+ /** Options for {@link modelGrants.invoke}. */
6
+ export interface ModelInvokeGrantOptions {
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.
11
+ *
12
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/guardrails-permissions-id.html
13
+ */
14
+ requireGuardrail?: Resolvable<GuardrailReference>;
15
+ }
4
16
  /**
5
17
  * Consumer-side grant helpers for invoking Amazon Bedrock models. Pass one to
6
18
  * a grantee builder's `grant(...)` — e.g.
@@ -22,6 +34,18 @@ export declare const modelGrants: {
22
34
  *
23
35
  * @see https://docs.aws.amazon.com/wellarchitected/latest/generative-ai-lens/gensec01-bp01.html
24
36
  */
25
- invoke: (target: Resolvable<InferenceTarget>) => Grant<IGrantable>;
37
+ invoke: (target: Resolvable<InferenceTarget>, { requireGuardrail }?: ModelInvokeGrantOptions) => Grant<IGrantable>;
38
+ };
39
+ /**
40
+ * Consumer-side grant helpers for Amazon Bedrock guardrails.
41
+ *
42
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/guardrails-permissions-id.html
43
+ */
44
+ export declare const guardrailGrants: {
45
+ /**
46
+ * Apply the guardrail (`bedrock:ApplyGuardrail`), through the
47
+ * `ApplyGuardrail` API or a model invocation that names it.
48
+ */
49
+ apply: (guardrail: Resolvable<GuardrailReference>) => Grant<IGrantable>;
26
50
  };
27
51
  //# sourceMappingURL=grants.d.ts.map
@@ -1 +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"}
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,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.modelGrants = void 0;
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
6
  const inference_target_js_1 = require("./inference-target.js");
@@ -11,6 +11,46 @@ const inference_target_js_1 = require("./inference-target.js");
11
11
  * @see https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonbedrock.html
12
12
  */
13
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}`;
17
+ }
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);
21
+ for (const { resourceArns, conditions } of statements) {
22
+ aws_iam_1.Grant.addToPrincipal({
23
+ grantee,
24
+ actions: INVOKE_ACTIONS,
25
+ resourceArns,
26
+ conditions: identifier
27
+ ? {
28
+ ...conditions,
29
+ StringEquals: {
30
+ ...conditions?.StringEquals,
31
+ "bedrock:GuardrailIdentifier": identifier,
32
+ },
33
+ }
34
+ : conditions,
35
+ });
36
+ }
37
+ if (!guardrail)
38
+ return;
39
+ grantee.grantPrincipal.addToPrincipalPolicy(new aws_iam_1.PolicyStatement({
40
+ effect: aws_iam_1.Effect.DENY,
41
+ actions: INVOKE_ACTIONS,
42
+ resources: statements.flatMap((s) => s.resourceArns),
43
+ conditions: { StringNotEquals: { "bedrock:GuardrailIdentifier": identifierOf(guardrail) } },
44
+ }));
45
+ grantApply(guardrail, grantee);
46
+ }
47
+ function grantApply(guardrail, grantee) {
48
+ aws_iam_1.Grant.addToPrincipal({
49
+ grantee,
50
+ actions: ["bedrock:ApplyGuardrail"],
51
+ resourceArns: [guardrail.guardrailArn],
52
+ });
53
+ }
14
54
  /**
15
55
  * Consumer-side grant helpers for invoking Amazon Bedrock models. Pass one to
16
56
  * a grantee builder's `grant(...)` — e.g.
@@ -32,11 +72,22 @@ exports.modelGrants = {
32
72
  *
33
73
  * @see https://docs.aws.amazon.com/wellarchitected/latest/generative-ai-lens/gensec01-bp01.html
34
74
  */
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
- }
75
+ invoke: (target, { requireGuardrail } = {}) => (0, core_1.grantVia)((0, core_1.combine)({ target, guardrail: requireGuardrail }), ({ target: resolved, guardrail }, grantee) => {
76
+ grantInvoke(resolved, grantee, guardrail);
77
+ }),
78
+ };
79
+ /**
80
+ * Consumer-side grant helpers for Amazon Bedrock guardrails.
81
+ *
82
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/guardrails-permissions-id.html
83
+ */
84
+ exports.guardrailGrants = {
85
+ /**
86
+ * Apply the guardrail (`bedrock:ApplyGuardrail`), through the
87
+ * `ApplyGuardrail` API or a model invocation that names it.
88
+ */
89
+ apply: (guardrail) => (0, core_1.grantVia)(guardrail, (resolved, grantee) => {
90
+ grantApply(resolved, grantee);
40
91
  }),
41
92
  };
42
93
  //# sourceMappingURL=grants.js.map
@@ -1 +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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EAAE,CAAC,QAAQ,EAAE,OAAmB,EAAE,EAAE;QACpD,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAChC,CAAC,CAAC;CACL,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { Metric, type MetricOptions } from "aws-cdk-lib/aws-cloudwatch";
2
+ import type { AlarmConfig, AlarmDefinition } from "@composurecdk/cloudwatch";
3
+ import type { GuardrailReference } from "./guardrail-builder.js";
4
+ /** `AWS/Bedrock/Guardrails` metrics for one guardrail version. */
5
+ export interface GuardrailMetrics {
6
+ /** A metric dimensioned by the guardrail's ARN and version. */
7
+ metric(metricName: string, options?: MetricOptions): Metric;
8
+ }
9
+ /** Returns the `AWS/Bedrock/Guardrails` metrics for `guardrail`. */
10
+ export declare function guardrailMetrics(guardrail: GuardrailReference): GuardrailMetrics;
11
+ /**
12
+ * Controls the recommended alarms for a guardrail. Both are opt-in and need a
13
+ * threshold: what counts as normal depends on the workload.
14
+ *
15
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/monitoring-guardrails-cw-metrics.html
16
+ */
17
+ export interface GuardrailAlarmConfig {
18
+ /**
19
+ * Master switch: set to `false` to disable all recommended alarms.
20
+ * @default true
21
+ */
22
+ enabled?: boolean;
23
+ /**
24
+ * Alarm when the guardrail intervenes more often than the threshold, e.g.
25
+ * a spike in prompt attacks or a filter set too strictly.
26
+ *
27
+ * Metric: `InvocationsIntervened`, statistic Sum. Opt-in; threshold required.
28
+ */
29
+ invocationsIntervened?: AlarmConfig | false;
30
+ /**
31
+ * Alarm when evaluating the guardrail takes longer than the threshold, in
32
+ * milliseconds.
33
+ *
34
+ * Metric: `InvocationLatency`, statistic p90. Opt-in; threshold required.
35
+ */
36
+ invocationLatency?: AlarmConfig | false;
37
+ }
38
+ /** Resolves the recommended guardrail alarms. */
39
+ export declare function resolveGuardrailAlarmDefinitions(metrics: GuardrailMetrics, config: GuardrailAlarmConfig | false | undefined): AlarmDefinition[];
40
+ //# sourceMappingURL=guardrail-alarms.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardrail-alarms.d.ts","sourceRoot":"","sources":["../../src/guardrail-alarms.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE7E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,kEAAkE;AAClE,MAAM,WAAW,gBAAgB;IAC/B,+DAA+D;IAC/D,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC;CAC7D;AAED,oEAAoE;AACpE,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,kBAAkB,GAAG,gBAAgB,CAchF;AAED;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;;OAKG;IACH,qBAAqB,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC;IAE5C;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC;CACzC;AAkBD,iDAAiD;AACjD,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,oBAAoB,GAAG,KAAK,GAAG,SAAS,GAC/C,eAAe,EAAE,CAKnB"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.guardrailMetrics = guardrailMetrics;
4
+ exports.resolveGuardrailAlarmDefinitions = resolveGuardrailAlarmDefinitions;
5
+ const aws_cdk_lib_1 = require("aws-cdk-lib");
6
+ const aws_cloudwatch_1 = require("aws-cdk-lib/aws-cloudwatch");
7
+ const alarm_definition_js_1 = require("./alarm-definition.js");
8
+ /** Returns the `AWS/Bedrock/Guardrails` metrics for `guardrail`. */
9
+ function guardrailMetrics(guardrail) {
10
+ return {
11
+ metric: (metricName, options) => new aws_cloudwatch_1.Metric({
12
+ namespace: "AWS/Bedrock/Guardrails",
13
+ metricName,
14
+ dimensionsMap: {
15
+ GuardrailArn: guardrail.guardrailArn,
16
+ GuardrailVersion: guardrail.version,
17
+ },
18
+ period: aws_cdk_lib_1.Duration.minutes(1),
19
+ ...options,
20
+ }),
21
+ };
22
+ }
23
+ const GUARDRAIL_ALARMS = {
24
+ invocationsIntervened: {
25
+ metricName: "InvocationsIntervened",
26
+ statistic: "Sum",
27
+ describe: (t) => `The guardrail is intervening more than ${String(t)} times a minute.`,
28
+ },
29
+ invocationLatency: {
30
+ metricName: "InvocationLatency",
31
+ statistic: "p90",
32
+ describe: (t) => `p90 guardrail evaluation latency exceeds ${String(t)} ms.`,
33
+ },
34
+ };
35
+ /** Resolves the recommended guardrail alarms. */
36
+ function resolveGuardrailAlarmDefinitions(metrics, config) {
37
+ if (config === false || config?.enabled === false)
38
+ return [];
39
+ return (0, alarm_definition_js_1.resolveThresholdAlarms)(GUARDRAIL_ALARMS, config, (metricName, statistic) => metrics.metric(metricName, { statistic }));
40
+ }
41
+ //# sourceMappingURL=guardrail-alarms.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardrail-alarms.js","sourceRoot":"","sources":["../../src/guardrail-alarms.ts"],"names":[],"mappings":";;AAaA,4CAcC;AAiDD,4EAQC;AApFD,6CAAuC;AACvC,+DAAwE;AAExE,+DAAwF;AASxF,oEAAoE;AACpE,SAAgB,gBAAgB,CAAC,SAA6B;IAC5D,OAAO;QACL,MAAM,EAAE,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE,CAC9B,IAAI,uBAAM,CAAC;YACT,SAAS,EAAE,wBAAwB;YACnC,UAAU;YACV,aAAa,EAAE;gBACb,YAAY,EAAE,SAAS,CAAC,YAAY;gBACpC,gBAAgB,EAAE,SAAS,CAAC,OAAO;aACpC;YACD,MAAM,EAAE,sBAAQ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