1/**
2 * Cross-region inference profile geo prefixes. A model id beginning with one
3 * of these (e.g. `us.amazon.nova-micro-v1:0`) is a system-defined inference
4 * profile id, not a foundation-model id.
5 */
6const INFERENCE_PROFILE_GEO_PREFIXES = new Set([
7 "us",
8 "us-gov",
9 "eu",
10 "apac",
11 "jp",
12 "au",
13 "global",
14]);
15
16/**
17 * Resolve the IAM policy `Resource` ARNs required to invoke a Bedrock model.
18 *
19 * Accepts any of the model reference forms `Converse`/`InvokeModel` accept:
20 *
21 * - a foundation-model id (`anthropic.claude-sonnet-4-20250514-v1:0`) —
22 * resolves to `arn:aws:bedrock:{region}::foundation-model/{modelId}`
23 * - a cross-region inference profile id (`us.amazon.nova-micro-v1:0`) —
24 * resolves to the account's inference-profile ARN *plus* the underlying
25 * foundation-model ARN in every region the profile can route to
26 * (`arn:aws:bedrock:*::foundation-model/{baseModelId}`), which Bedrock
27 * requires for cross-region invocation
28 * - a full ARN (foundation model, inference profile, application inference
29 * profile, imported/custom model, or prompt ARN) — passed through as-is
30 */
31export const bedrockModelArns = (
32 region: string,
33 accountId: string,
34 modelId: string,
35): string[] => {
36 if (modelId.startsWith("arn:")) {
37 return [modelId];
38 }
39 const geoPrefix = modelId.split(".", 1)[0];
40 if (geoPrefix && INFERENCE_PROFILE_GEO_PREFIXES.has(geoPrefix)) {
41 return [
42 `arn:aws:bedrock:${region}:${accountId}:inference-profile/${modelId}`,
43 `arn:aws:bedrock:*::foundation-model/${modelId.slice(geoPrefix.length + 1)}`,
44 ];
45 }
46 return [`arn:aws:bedrock:${region}::foundation-model/${modelId}`];
47};