@composurecdk/bedrock 0.11.1 → 0.12.0
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.
- package/README.md +41 -21
- package/dist/commonjs/arn.d.ts +12 -0
- package/dist/commonjs/arn.d.ts.map +1 -0
- package/dist/commonjs/arn.js +27 -0
- package/dist/commonjs/arn.js.map +1 -0
- package/dist/commonjs/grants.d.ts +27 -9
- package/dist/commonjs/grants.d.ts.map +1 -1
- package/dist/commonjs/grants.js +68 -30
- package/dist/commonjs/grants.js.map +1 -1
- package/dist/commonjs/index.d.ts +1 -1
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +2 -1
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/inference-profile.d.ts +25 -9
- package/dist/commonjs/inference-profile.d.ts.map +1 -1
- package/dist/commonjs/inference-profile.js +41 -25
- package/dist/commonjs/inference-profile.js.map +1 -1
- package/dist/commonjs/inference-target.d.ts +42 -4
- package/dist/commonjs/inference-target.d.ts.map +1 -1
- package/dist/commonjs/inference-target.js +72 -25
- package/dist/commonjs/inference-target.js.map +1 -1
- package/dist/esm/arn.d.ts +12 -0
- package/dist/esm/arn.d.ts.map +1 -0
- package/dist/esm/arn.js +23 -0
- package/dist/esm/arn.js.map +1 -0
- package/dist/esm/grants.d.ts +27 -9
- package/dist/esm/grants.d.ts.map +1 -1
- package/dist/esm/grants.js +69 -31
- package/dist/esm/grants.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/inference-profile.d.ts +25 -9
- package/dist/esm/inference-profile.d.ts.map +1 -1
- package/dist/esm/inference-profile.js +39 -25
- package/dist/esm/inference-profile.js.map +1 -1
- package/dist/esm/inference-target.d.ts +42 -4
- package/dist/esm/inference-target.d.ts.map +1 -1
- package/dist/esm/inference-target.js +66 -20
- package/dist/esm/inference-target.js.map +1 -1
- package/package.json +9 -9
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.inferenceProfile = exports.INFERENCE_PROFILE_GEOGRAPHIES = void 0;
|
|
4
|
+
exports.idPrefix = idPrefix;
|
|
5
|
+
exports.assertLiteralId = assertLiteralId;
|
|
4
6
|
exports.foundationModelFor = foundationModelFor;
|
|
5
7
|
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
|
6
8
|
const aws_bedrock_1 = require("aws-cdk-lib/aws-bedrock");
|
|
@@ -14,32 +16,48 @@ const aws_bedrock_1 = require("aws-cdk-lib/aws-bedrock");
|
|
|
14
16
|
*
|
|
15
17
|
* @see https://docs.aws.amazon.com/bedrock/latest/userguide/geographic-cross-region-inference.html
|
|
16
18
|
*/
|
|
17
|
-
exports.INFERENCE_PROFILE_GEOGRAPHIES = [
|
|
19
|
+
exports.INFERENCE_PROFILE_GEOGRAPHIES = [
|
|
20
|
+
"us",
|
|
21
|
+
"eu",
|
|
22
|
+
"apac",
|
|
23
|
+
"jp",
|
|
24
|
+
"au",
|
|
25
|
+
"in",
|
|
26
|
+
"us-gov",
|
|
27
|
+
];
|
|
18
28
|
const GLOBAL_PREFIX = "global";
|
|
29
|
+
const PROFILE_PREFIXES = [GLOBAL_PREFIX, ...exports.INFERENCE_PROFILE_GEOGRAPHIES];
|
|
19
30
|
const GEOGRAPHY_PATTERN = /^[a-z]+(-[a-z]+)*$/;
|
|
20
31
|
const REGION_PATTERN = /^[a-z]{2}(-[a-z]+)+-\d+$/;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
/**
|
|
33
|
+
* The segment of `id` before its first dot, and whether it marks a
|
|
34
|
+
* system-defined profile id. Undefined when `id` has no such segment.
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
function idPrefix(id) {
|
|
26
38
|
const dot = id.indexOf(".");
|
|
27
|
-
|
|
39
|
+
if (dot <= 0)
|
|
40
|
+
return undefined;
|
|
41
|
+
const prefix = id.slice(0, dot);
|
|
42
|
+
return { prefix, isProfile: PROFILE_PREFIXES.includes(prefix) };
|
|
43
|
+
}
|
|
44
|
+
/** Throws unless `id` is a non-empty literal string. @internal */
|
|
45
|
+
function assertLiteralId(id, label) {
|
|
46
|
+
if (aws_cdk_lib_1.Token.isUnresolved(id) || id === "") {
|
|
47
|
+
throw new Error(`${label} must be a non-empty literal string.`);
|
|
48
|
+
}
|
|
28
49
|
}
|
|
29
50
|
function assertModel(model) {
|
|
30
51
|
const { modelId } = model;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
const prefix = prefixOf(modelId);
|
|
35
|
-
if (prefix !== undefined && isProfilePrefix(prefix)) {
|
|
52
|
+
assertLiteralId(modelId, "Inference profile model id");
|
|
53
|
+
if (idPrefix(modelId)?.isProfile) {
|
|
36
54
|
throw new Error(`"${modelId}" is an inference profile id, not a foundation model id. ` +
|
|
37
|
-
`Use inferenceProfile.parse("${modelId}"
|
|
55
|
+
`Use inferenceProfile.parse("${modelId}") instead.`);
|
|
38
56
|
}
|
|
39
57
|
}
|
|
40
58
|
function assertRoutingRegions(profileId, regions) {
|
|
41
59
|
if (regions.length === 0) {
|
|
42
|
-
throw new Error(`Inference profile "${profileId}": routingRegions must not be empty.`);
|
|
60
|
+
throw new Error(`Inference profile "${profileId}": routingRegions must not be empty; omit it to grant every Region.`);
|
|
43
61
|
}
|
|
44
62
|
for (const region of regions) {
|
|
45
63
|
if (aws_cdk_lib_1.Token.isUnresolved(region) || !REGION_PATTERN.test(region)) {
|
|
@@ -48,19 +66,20 @@ function assertRoutingRegions(profileId, regions) {
|
|
|
48
66
|
}
|
|
49
67
|
}
|
|
50
68
|
function geographic(options) {
|
|
51
|
-
const { model, geography } = options;
|
|
69
|
+
const { model, geography, routingRegions } = options;
|
|
52
70
|
assertModel(model);
|
|
53
71
|
if (geography === GLOBAL_PREFIX || !GEOGRAPHY_PATTERN.test(geography)) {
|
|
54
72
|
throw new Error(`"${geography}" is not a geography prefix. Use inferenceProfile.global() for a global profile.`);
|
|
55
73
|
}
|
|
56
74
|
const profileId = `${geography}.${model.modelId}`;
|
|
57
|
-
|
|
75
|
+
if (routingRegions !== undefined)
|
|
76
|
+
assertRoutingRegions(profileId, routingRegions);
|
|
58
77
|
return Object.freeze({
|
|
59
78
|
kind: "geographic",
|
|
60
79
|
geography,
|
|
61
80
|
model,
|
|
62
81
|
profileId,
|
|
63
|
-
routingRegions: Object.freeze([...new Set(
|
|
82
|
+
...(routingRegions && { routingRegions: Object.freeze([...new Set(routingRegions)]) }),
|
|
64
83
|
});
|
|
65
84
|
}
|
|
66
85
|
function global(model) {
|
|
@@ -68,11 +87,12 @@ function global(model) {
|
|
|
68
87
|
return Object.freeze({ kind: "global", model, profileId: `${GLOBAL_PREFIX}.${model.modelId}` });
|
|
69
88
|
}
|
|
70
89
|
function splitProfileId(profileId) {
|
|
71
|
-
const
|
|
72
|
-
if (
|
|
90
|
+
const parsed = idPrefix(profileId);
|
|
91
|
+
if (!parsed?.isProfile) {
|
|
73
92
|
throw new Error(`"${profileId}" is not a system-defined inference profile id. Expected one of the ` +
|
|
74
|
-
`prefixes: ${
|
|
93
|
+
`prefixes: ${PROFILE_PREFIXES.join(", ")}.`);
|
|
75
94
|
}
|
|
95
|
+
const { prefix } = parsed;
|
|
76
96
|
return { prefix, modelId: profileId.slice(prefix.length + 1) };
|
|
77
97
|
}
|
|
78
98
|
function parse(profileId, routingRegions) {
|
|
@@ -84,9 +104,6 @@ function parse(profileId, routingRegions) {
|
|
|
84
104
|
}
|
|
85
105
|
return global(model);
|
|
86
106
|
}
|
|
87
|
-
if (routingRegions === undefined) {
|
|
88
|
-
throw new Error(`Inference profile "${profileId}" is geographic and needs its routingRegions.`);
|
|
89
|
-
}
|
|
90
107
|
return geographic({ model, geography: prefix, routingRegions });
|
|
91
108
|
}
|
|
92
109
|
/**
|
|
@@ -97,7 +114,6 @@ function parse(profileId, routingRegions) {
|
|
|
97
114
|
* const haiku = inferenceProfile.geographic({
|
|
98
115
|
* model: FoundationModelIdentifier.ANTHROPIC_CLAUDE_HAIKU_4_5_20251001_V1_0,
|
|
99
116
|
* geography: "eu",
|
|
100
|
-
* routingRegions: ["eu-central-1", "eu-north-1", "eu-south-1", "eu-south-2", "eu-west-1", "eu-west-3"],
|
|
101
117
|
* });
|
|
102
118
|
* haiku.profileId; // "eu.anthropic.claude-haiku-4-5-20251001-v1:0"
|
|
103
119
|
* ```
|
|
@@ -110,7 +126,7 @@ exports.inferenceProfile = {
|
|
|
110
126
|
/**
|
|
111
127
|
* Reads a profile id such as `eu.anthropic.claude-haiku-4-5-20251001-v1:0`.
|
|
112
128
|
* Throws unless the id starts with a known geography or `global`. A
|
|
113
|
-
* geographic id
|
|
129
|
+
* geographic id may take its `routingRegions`; a global id takes none.
|
|
114
130
|
*/
|
|
115
131
|
parse,
|
|
116
132
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inference-profile.js","sourceRoot":"","sources":["../../src/inference-profile.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"inference-profile.js","sourceRoot":"","sources":["../../src/inference-profile.ts"],"names":[],"mappings":";;;AA6GA,4BAKC;AAGD,0CAIC;AA4GD,gDAEC;AAvOD,6CAAoC;AACpC,yDAAoE;AAEpE;;;;;;;;;GASG;AACU,QAAA,6BAA6B,GAAG;IAC3C,IAAI;IACJ,IAAI;IACJ,MAAM;IACN,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,QAAQ;CACA,CAAC;AAKX,MAAM,aAAa,GAAG,QAAQ,CAAC;AAE/B,MAAM,gBAAgB,GAAsB,CAAC,aAAa,EAAE,GAAG,qCAA6B,CAAC,CAAC;AAyE9F,MAAM,iBAAiB,GAAG,oBAAoB,CAAC;AAC/C,MAAM,cAAc,GAAG,0BAA0B,CAAC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,aAAa,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAC9C,CAAC;IACJ,CAAC;IACD,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAC1B,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC;AACjE,CAAC;AAED,SAAS,KAAK,CAAC,SAAiB,EAAE,cAAkC;IAClE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC;IACtD,MAAM,KAAK,GAAG,IAAI,uCAAyB,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;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"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FoundationModelIdentifier, type IModel } from "aws-cdk-lib/aws-bedrock";
|
|
2
2
|
import { type IConstruct } from "constructs";
|
|
3
|
-
import type
|
|
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":"
|
|
1
|
+
{"version":3,"file":"inference-target.d.ts","sourceRoot":"","sources":["../../src/inference-target.ts"],"names":[],"mappings":"AAAA,O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AAM,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,wBAA6B,GAAG,eAAe,CA6BnF;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe;IAC1B,+EAA+E;;CAEhF,CAAC"}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.inferenceTarget = void 0;
|
|
3
4
|
exports.isInferenceProfile = isInferenceProfile;
|
|
4
5
|
exports.invocationStatements = invocationStatements;
|
|
5
6
|
exports.sourceArn = sourceArn;
|
|
6
7
|
exports.invocationArns = invocationArns;
|
|
7
8
|
exports.scopeOf = scopeOf;
|
|
8
|
-
const
|
|
9
|
+
const aws_bedrock_1 = require("aws-cdk-lib/aws-bedrock");
|
|
9
10
|
const constructs_1 = require("constructs");
|
|
11
|
+
const arn_js_1 = require("./arn.js");
|
|
12
|
+
const inference_profile_js_1 = require("./inference-profile.js");
|
|
10
13
|
/** @internal */
|
|
11
14
|
function isInferenceProfile(target) {
|
|
12
15
|
return "kind" in target && (target.kind === "geographic" || target.kind === "global");
|
|
@@ -17,26 +20,12 @@ function isApplicationProfile(target) {
|
|
|
17
20
|
function isModel(target) {
|
|
18
21
|
return "modelArn" in target;
|
|
19
22
|
}
|
|
20
|
-
function environmentOf(scope) {
|
|
21
|
-
return scope === undefined
|
|
22
|
-
? { partition: aws_cdk_lib_1.Aws.PARTITION, region: aws_cdk_lib_1.Aws.REGION, account: aws_cdk_lib_1.Aws.ACCOUNT_ID }
|
|
23
|
-
: aws_cdk_lib_1.Stack.of(scope);
|
|
24
|
-
}
|
|
25
|
-
function bedrockArn(partition, resource, resourceName, region, account = "") {
|
|
26
|
-
return aws_cdk_lib_1.Arn.format({
|
|
27
|
-
partition,
|
|
28
|
-
service: "bedrock",
|
|
29
|
-
region,
|
|
30
|
-
account,
|
|
31
|
-
resource,
|
|
32
|
-
resourceName,
|
|
33
|
-
arnFormat: aws_cdk_lib_1.ArnFormat.SLASH_RESOURCE_NAME,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
23
|
/**
|
|
37
24
|
* The statements for invoking `target` from the Region `scope` deploys to:
|
|
38
25
|
* those the Bedrock user guide prescribes, and for an application profile the
|
|
39
|
-
* shape verified against live IAM.
|
|
26
|
+
* shape verified against live IAM. A geographic profile without
|
|
27
|
+
* `routingRegions` grants the model in every Region rather than an
|
|
28
|
+
* enumerated list, still only through the profile (#628).
|
|
40
29
|
*
|
|
41
30
|
* @see https://docs.aws.amazon.com/bedrock/latest/userguide/geographic-cross-region-inference.html#geographic-cris-iam-setup
|
|
42
31
|
* @see https://docs.aws.amazon.com/bedrock/latest/userguide/global-cross-region-inference.html#global-cris-iam-setup
|
|
@@ -60,8 +49,8 @@ function invocationStatements(target, scope) {
|
|
|
60
49
|
* itself (verified live for a global source), so none is granted.
|
|
61
50
|
*/
|
|
62
51
|
function sourceStatements(target, scope, viaProfile) {
|
|
63
|
-
const { partition, region: sourceRegion } = environmentOf(scope);
|
|
64
|
-
const modelArn = (modelId, region) => bedrockArn(partition, "foundation-model", modelId, region);
|
|
52
|
+
const { partition, region: sourceRegion } = (0, arn_js_1.environmentOf)(scope);
|
|
53
|
+
const modelArn = (modelId, region) => (0, arn_js_1.bedrockArn)(partition, "foundation-model", modelId, region);
|
|
65
54
|
const through = (arn) => ({ "bedrock:InferenceProfileArn": arn });
|
|
66
55
|
if (!isInferenceProfile(target)) {
|
|
67
56
|
return [
|
|
@@ -83,7 +72,9 @@ function sourceStatements(target, scope, viaProfile) {
|
|
|
83
72
|
const models = target.kind === "geographic"
|
|
84
73
|
? [
|
|
85
74
|
{
|
|
86
|
-
resourceArns:
|
|
75
|
+
resourceArns: (target.routingRegions
|
|
76
|
+
? [...new Set([sourceRegion, ...target.routingRegions])]
|
|
77
|
+
: ["*"]).map((region) => modelArn(modelId, region)),
|
|
87
78
|
conditions: { StringEquals: via },
|
|
88
79
|
},
|
|
89
80
|
]
|
|
@@ -104,10 +95,10 @@ function sourceStatements(target, scope, viaProfile) {
|
|
|
104
95
|
* or the system-defined profile. @internal
|
|
105
96
|
*/
|
|
106
97
|
function sourceArn(source, scope) {
|
|
107
|
-
const { partition, region, account } = environmentOf(scope);
|
|
98
|
+
const { partition, region, account } = (0, arn_js_1.environmentOf)(scope);
|
|
108
99
|
return isInferenceProfile(source)
|
|
109
|
-
? bedrockArn(partition, "inference-profile", source.profileId, region, account)
|
|
110
|
-
: bedrockArn(partition, "foundation-model", source.modelId, region);
|
|
100
|
+
? (0, arn_js_1.bedrockArn)(partition, "inference-profile", source.profileId, region, account)
|
|
101
|
+
: (0, arn_js_1.bedrockArn)(partition, "foundation-model", source.modelId, region);
|
|
111
102
|
}
|
|
112
103
|
/**
|
|
113
104
|
* Every resource ARN a caller in `scope`'s Region must be allowed to invoke to
|
|
@@ -117,7 +108,9 @@ function sourceArn(source, scope) {
|
|
|
117
108
|
*
|
|
118
109
|
* {@link modelGrants.invoke} applies these with the conditions the Bedrock
|
|
119
110
|
* user guide prescribes; use this list where you write a policy yourself,
|
|
120
|
-
* such as a service control policy.
|
|
111
|
+
* such as a service control policy. A geographic profile without
|
|
112
|
+
* `routingRegions` yields one Region-wildcard model ARN, so list the Regions
|
|
113
|
+
* on the profile when the policy must name each one.
|
|
121
114
|
*
|
|
122
115
|
* @param scope - Resolves partition, Region and account from its stack. Omit
|
|
123
116
|
* for the `AWS::` pseudo-parameters.
|
|
@@ -129,4 +122,58 @@ function invocationArns(target, scope) {
|
|
|
129
122
|
function scopeOf(principal) {
|
|
130
123
|
return constructs_1.Construct.isConstruct(principal) ? principal : undefined;
|
|
131
124
|
}
|
|
125
|
+
const PROVISIONED_MODEL_ARN = ":provisioned-model/";
|
|
126
|
+
/**
|
|
127
|
+
* Resolves an id that arrives as a string, such as from configuration, to the
|
|
128
|
+
* target it names:
|
|
129
|
+
*
|
|
130
|
+
* - `anthropic.claude-…` → a `FoundationModelIdentifier`;
|
|
131
|
+
* - `eu.anthropic.claude-…` or `global.anthropic.claude-…` → a system-defined
|
|
132
|
+
* profile, via {@link inferenceProfile.parse};
|
|
133
|
+
* - a provisioned-model ARN → `{ modelArn }`.
|
|
134
|
+
*
|
|
135
|
+
* A two-segment id with an unknown first segment throws rather than being
|
|
136
|
+
* taken for a model named after a geography. A system-defined or application
|
|
137
|
+
* profile ARN throws too: the model it routes to cannot be read from it, and
|
|
138
|
+
* a grant on the ARN alone would be incomplete. Pass the profile value instead.
|
|
139
|
+
*/
|
|
140
|
+
function fromId(id, options = {}) {
|
|
141
|
+
(0, inference_profile_js_1.assertLiteralId)(id, "Inference target id");
|
|
142
|
+
if (id.startsWith("arn:")) {
|
|
143
|
+
if (id.includes(PROVISIONED_MODEL_ARN))
|
|
144
|
+
return { modelArn: id };
|
|
145
|
+
throw new Error(`"${id}" is an ARN. inferenceTarget.fromId resolves foundation-model and system-defined ` +
|
|
146
|
+
`profile ids, and provisioned-model ARNs. For an inference profile pass its id, or an ` +
|
|
147
|
+
`ApplicationInferenceProfile value, so the model it routes to is granted as well.`);
|
|
148
|
+
}
|
|
149
|
+
const parsed = (0, inference_profile_js_1.idPrefix)(id);
|
|
150
|
+
if (!parsed) {
|
|
151
|
+
throw new Error(`"${id}" is not a foundation model or inference profile id.`);
|
|
152
|
+
}
|
|
153
|
+
const { prefix, isProfile } = parsed;
|
|
154
|
+
if (isProfile)
|
|
155
|
+
return inference_profile_js_1.inferenceProfile.parse(id, options.routingRegions);
|
|
156
|
+
if (id.includes(".", prefix.length + 1)) {
|
|
157
|
+
throw new Error(`"${id}" looks like an inference profile id, but "${prefix}" is neither global nor one ` +
|
|
158
|
+
`of INFERENCE_PROFILE_GEOGRAPHIES (${inference_profile_js_1.INFERENCE_PROFILE_GEOGRAPHIES.join(", ")}). ` +
|
|
159
|
+
`For a new geography use inferenceProfile.geographic().`);
|
|
160
|
+
}
|
|
161
|
+
if (options.routingRegions !== undefined) {
|
|
162
|
+
throw new Error(`"${id}" is a foundation model id; routingRegions apply to a geographic profile.`);
|
|
163
|
+
}
|
|
164
|
+
return new aws_bedrock_1.FoundationModelIdentifier(id);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Factories for {@link InferenceTarget} values.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* const ids = ["anthropic.claude-sonnet-5-5", "us.anthropic.claude-haiku-4-5-20251001-v1:0"];
|
|
172
|
+
* createFunctionBuilder().grant(...ids.map((id) => modelGrants.invoke(inferenceTarget.fromId(id))));
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
exports.inferenceTarget = {
|
|
176
|
+
/** Resolves a model id, system-defined profile id or provisioned-model ARN. */
|
|
177
|
+
fromId,
|
|
178
|
+
};
|
|
132
179
|
//# sourceMappingURL=inference-target.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inference-target.js","sourceRoot":"","sources":["../../src/inference-target.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"inference-target.js","sourceRoot":"","sources":["../../src/inference-target.ts"],"names":[],"mappings":";;;AAqBA,gDAEC;AA2BD,oDAYC;AAiED,8BAQC;AAiBD,wCAEC;AAGD,0BAEC;AA/JD,yDAAiF;AACjF,2CAAwD;AACxD,qCAAqD;AACrD,iEAOgC;AAUhC,gBAAgB;AAChB,SAAgB,kBAAkB,CAAC,MAAuB;IACxD,OAAO,MAAM,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,YAAY,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC;AACxF,CAAC;AAED,SAAS,oBAAoB,CAAC,MAAuB;IACnD,OAAO,MAAM,IAAI,MAAM,IAAI,MAAM,CAAC,IAAI,KAAK,aAAa,CAAC;AAC3D,CAAC;AAED,SAAS,OAAO,CAAC,MAAuB;IACtC,OAAO,UAAU,IAAI,MAAM,CAAC;AAC9B,CAAC;AAQD;;;;;;;;;;GAUG;AACH,SAA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FAAuF;YACvF,kFAAkF,CACrF,CAAC;IACJ,CAAC;IACD,MAAM,MAAM,GAAG,IAAA,+BAAQ,EAAC,EAAE,CAAC,CAAC;IAC5B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,IAAI,EAAE,sDAAsD,CAAC,CAAC;IAChF,CAAC;IACD,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IACrC,IAAI,SAAS;QAAE,OAAO,uCAAgB,CAAC,KAAK,CAAC,EAAE,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;IACzE,IAAI,EAAE,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CACb,IAAI,EAAE,8CAA8C,MAAM,8BAA8B;YACtF,qCAAqC,oDAA6B,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK;YAClF,wDAAwD,CAC3D,CAAC;IACJ,CAAC;IACD,IAAI,OAAO,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;QACzC,MAAM,IAAI,KAAK,CACb,IAAI,EAAE,2EAA2E,CAClF,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,uCAAyB,CAAC,EAAE,CAAC,CAAC;AAC3C,CAAC;AAED;;;;;;;;GAQG;AACU,QAAA,eAAe,GAAG;IAC7B,+EAA+E;IAC/E,MAAM;CACP,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Stack } from "aws-cdk-lib";
|
|
2
|
+
import type { IConstruct } from "constructs";
|
|
3
|
+
type Environment = Pick<Stack, "partition" | "region" | "account">;
|
|
4
|
+
/**
|
|
5
|
+
* The partition, Region and account of `scope`'s stack, or the `AWS::`
|
|
6
|
+
* pseudo-parameters without a scope. @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare function environmentOf(scope: IConstruct | undefined): Environment;
|
|
9
|
+
/** A `bedrock` ARN with a slash-separated resource name. @internal */
|
|
10
|
+
export declare function bedrockArn(partition: string, resource: string, resourceName: string, region: string, account?: string): string;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=arn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arn.d.ts","sourceRoot":"","sources":["../../src/arn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,KAAK,WAAW,GAAG,IAAI,CAAC,KAAK,EAAE,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC,CAAC;AAEnE;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,WAAW,CAIxE;AAED,sEAAsE;AACtE,wBAAgB,UAAU,CACxB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,EACd,OAAO,SAAK,GACX,MAAM,CAUR"}
|
package/dist/esm/arn.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Arn, ArnFormat, Aws, Stack } from "aws-cdk-lib";
|
|
2
|
+
/**
|
|
3
|
+
* The partition, Region and account of `scope`'s stack, or the `AWS::`
|
|
4
|
+
* pseudo-parameters without a scope. @internal
|
|
5
|
+
*/
|
|
6
|
+
export function environmentOf(scope) {
|
|
7
|
+
return scope === undefined
|
|
8
|
+
? { partition: Aws.PARTITION, region: Aws.REGION, account: Aws.ACCOUNT_ID }
|
|
9
|
+
: Stack.of(scope);
|
|
10
|
+
}
|
|
11
|
+
/** A `bedrock` ARN with a slash-separated resource name. @internal */
|
|
12
|
+
export function bedrockArn(partition, resource, resourceName, region, account = "") {
|
|
13
|
+
return Arn.format({
|
|
14
|
+
partition,
|
|
15
|
+
service: "bedrock",
|
|
16
|
+
region,
|
|
17
|
+
account,
|
|
18
|
+
resource,
|
|
19
|
+
resourceName,
|
|
20
|
+
arnFormat: ArnFormat.SLASH_RESOURCE_NAME,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=arn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arn.js","sourceRoot":"","sources":["../../src/arn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAKzD;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,KAA6B;IACzD,OAAO,KAAK,KAAK,SAAS;QACxB,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,UAAU,EAAE;QAC3E,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;AACtB,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,UAAU,CACxB,SAAiB,EACjB,QAAgB,EAChB,YAAoB,EACpB,MAAc,EACd,OAAO,GAAG,EAAE;IAEZ,OAAO,GAAG,CAAC,MAAM,CAAC;QAChB,SAAS;QACT,OAAO,EAAE,SAAS;QAClB,MAAM;QACN,OAAO;QACP,QAAQ;QACR,YAAY;QACZ,SAAS,EAAE,SAAS,CAAC,mBAAmB;KACzC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/esm/grants.d.ts
CHANGED
|
@@ -5,13 +5,25 @@ import { type InferenceTarget } from "./inference-target.js";
|
|
|
5
5
|
/** Options for {@link modelGrants.invoke}. */
|
|
6
6
|
export interface ModelInvokeGrantOptions {
|
|
7
7
|
/**
|
|
8
|
-
* Requires every invocation to apply
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* Requires every invocation to apply a guardrail. The allow is conditioned
|
|
9
|
+
* on `bedrock:GuardrailIdentifier`, an explicit deny refuses calls without
|
|
10
|
+
* it, and the grantee may apply the guardrail.
|
|
11
|
+
*
|
|
12
|
+
* A reference requires that guardrail version. `"any"` requires some
|
|
13
|
+
* guardrail in the grantee's account and Region, for a workload that picks
|
|
14
|
+
* its guardrail at run time; prefer a reference where the guardrail is
|
|
15
|
+
* known at synth.
|
|
11
16
|
*
|
|
12
17
|
* @see https://docs.aws.amazon.com/bedrock/latest/userguide/guardrails-permissions-id.html
|
|
13
18
|
*/
|
|
14
|
-
requireGuardrail?: Resolvable<GuardrailReference>;
|
|
19
|
+
requireGuardrail?: Resolvable<GuardrailReference | "any">;
|
|
20
|
+
/**
|
|
21
|
+
* Whether to grant `bedrock:InvokeModelWithResponseStream` alongside
|
|
22
|
+
* `bedrock:InvokeModel`. Set `false` for a caller that never streams.
|
|
23
|
+
*
|
|
24
|
+
* @default true
|
|
25
|
+
*/
|
|
26
|
+
streaming?: boolean;
|
|
15
27
|
}
|
|
16
28
|
/**
|
|
17
29
|
* Consumer-side grant helpers for invoking Amazon Bedrock models. Pass one to
|
|
@@ -27,14 +39,14 @@ export declare const modelGrants: {
|
|
|
27
39
|
* Invoke the target through `InvokeModel`, `Converse` or their streaming
|
|
28
40
|
* variants.
|
|
29
41
|
*
|
|
30
|
-
* For a cross-Region profile this also grants the foundation model in
|
|
31
|
-
*
|
|
32
|
-
* `bedrock:InferenceProfileArn` so
|
|
33
|
-
*
|
|
42
|
+
* For a cross-Region profile this also grants the foundation model, in
|
|
43
|
+
* every Region or in the profile's listed `routingRegions`, conditioned on
|
|
44
|
+
* `bedrock:InferenceProfileArn` so the model is reachable only through the
|
|
45
|
+
* profile.
|
|
34
46
|
*
|
|
35
47
|
* @see https://docs.aws.amazon.com/wellarchitected/latest/generative-ai-lens/gensec01-bp01.html
|
|
36
48
|
*/
|
|
37
|
-
invoke: (target: Resolvable<InferenceTarget>, { requireGuardrail }?: ModelInvokeGrantOptions) => Grant<IGrantable>;
|
|
49
|
+
invoke: (target: Resolvable<InferenceTarget>, { requireGuardrail, streaming }?: ModelInvokeGrantOptions) => Grant<IGrantable>;
|
|
38
50
|
};
|
|
39
51
|
/**
|
|
40
52
|
* Consumer-side grant helpers for Amazon Bedrock guardrails.
|
|
@@ -47,5 +59,11 @@ export declare const guardrailGrants: {
|
|
|
47
59
|
* `ApplyGuardrail` API or a model invocation that names it.
|
|
48
60
|
*/
|
|
49
61
|
apply: (guardrail: Resolvable<GuardrailReference>) => Grant<IGrantable>;
|
|
62
|
+
/**
|
|
63
|
+
* Apply any guardrail in the grantee's account and Region, for a caller
|
|
64
|
+
* that may name one at run time. Where the guardrail is known, `apply` it;
|
|
65
|
+
* where every call must carry one, `modelGrants.invoke(…, { requireGuardrail })`.
|
|
66
|
+
*/
|
|
67
|
+
applyAny: () => Grant<IGrantable>;
|
|
50
68
|
};
|
|
51
69
|
//# sourceMappingURL=grants.d.ts.map
|
package/dist/esm/grants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grants.d.ts","sourceRoot":"","sources":["../../src/grants.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,UAAU,EAAmB,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"grants.d.ts","sourceRoot":"","sources":["../../src/grants.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,UAAU,EAAmB,MAAM,qBAAqB,CAAC;AAElG,OAAO,EAAW,KAAK,KAAK,EAAY,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACpF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,EACL,KAAK,eAAe,EAIrB,MAAM,uBAAuB,CAAC;AAY/B,8CAA8C;AAC9C,MAAM,WAAW,uBAAuB;IACtC;;;;;;;;;;;OAWG;IACH,gBAAgB,CAAC,EAAE,UAAU,CAAC,kBAAkB,GAAG,KAAK,CAAC,CAAC;IAC1D;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AA8FD;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW;IACtB;;;;;;;;;;OAUG;qBAEO,UAAU,CAAC,eAAe,CAAC,oCACK,uBAAuB,KAC9D,KAAK,CAAC,UAAU,CAAC;CAOrB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,eAAe;IAC1B;;;OAGG;uBACgB,UAAU,CAAC,kBAAkB,CAAC,KAAG,KAAK,CAAC,UAAU,CAAC;IAIrE;;;;OAIG;oBAGW,KAAK,CAAC,UAAU,CAAC;CAKhC,CAAC"}
|