Skip to content

Commit 76b2d98

Browse files
authored
replace AIP with IAM principal tag (#1530)
1 parent 560dff0 commit 76b2d98

10 files changed

Lines changed: 2251 additions & 672 deletions

File tree

packages/cdk/lambda/speechToSpeechTask.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -416,29 +416,8 @@ export const handler = async (event: { channelId: string; model: Model }) => {
416416
try {
417417
console.log('event', event);
418418

419-
// Speech-to-Speech Inference Profile Arn handling
420-
// NOTE: InvokeModelWithBidirectionalStreamCommand currently does not support Inference Profile Arn.
421-
// When AWS adds support, uncomment the code block below and change 'const' to 'let' for modelIdOrArn.
422-
423-
const modelIdOrArn = event.model.modelId; // Fallback to modelId for now
424-
425-
/*
426-
// TODO: Uncomment this block when InvokeModelWithBidirectionalStreamCommand supports Inference Profile Arn
427-
// Also change 'const modelIdOrArn' above to 'let modelIdOrArn'
428-
try {
429-
const speechToSpeechModels = JSON.parse(process.env.SPEECH_TO_SPEECH_MODEL_IDS || '[]');
430-
const modelConfig = speechToSpeechModels.find((config: any) => config.modelId === event.model.modelId);
431-
if (modelConfig?.inferenceProfileArn) {
432-
modelIdOrArn = modelConfig.inferenceProfileArn;
433-
console.log('DEBUG: Using Inference Profile ARN for speech-to-speech:', modelIdOrArn);
434-
} else {
435-
console.log('DEBUG: No inference profile ARN found, using modelId:', modelIdOrArn);
436-
}
437-
} catch (error) {
438-
console.error('DEBUG: Error parsing SPEECH_TO_SPEECH_MODEL_IDS:', error);
439-
console.log('DEBUG: Falling back to modelId:', modelIdOrArn);
440-
}
441-
*/
419+
// Use modelId directly for speech-to-speech
420+
const modelIdOrArn = event.model.modelId;
442421

443422
initialize();
444423

packages/cdk/lambda/utils/bedrockApi.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
BEDROCK_TEXT_GEN_MODELS,
2525
BEDROCK_IMAGE_GEN_MODELS,
2626
BEDROCK_VIDEO_GEN_MODELS,
27-
getInferenceProfileArn,
2827
} from './models';
2928
import { streamingChunk } from './streamingChunk';
3029
import { initBedrockRuntimeClient } from './bedrockClient';
@@ -182,9 +181,8 @@ const bedrockApi: Omit<ApiInterface, 'invokeFlow'> = {
182181
const client = await initBedrockRuntimeClient({ region });
183182

184183
// Image generation using Stable Diffusion or Titan Image Generator is not supported for the Converse API, so InvokeModelCommand is used.
185-
const modelIdOrArn = getInferenceProfileArn(model.modelId) || model.modelId;
186184
const command = new InvokeModelCommand({
187-
modelId: modelIdOrArn,
185+
modelId: model.modelId,
188186
body: createBodyImage(model, params),
189187
contentType: 'application/json',
190188
});
@@ -205,9 +203,8 @@ const bedrockApi: Omit<ApiInterface, 'invokeFlow'> = {
205203
throw new Error('Video tmp buket is not defined');
206204
}
207205

208-
const modelIdOrArn = getInferenceProfileArn(model.modelId) || model.modelId;
209206
const command = new StartAsyncInvokeCommand({
210-
modelId: modelIdOrArn,
207+
modelId: model.modelId,
211208
modelInput: createBodyVideo(model, params),
212209
outputDataConfig: {
213210
s3OutputDataConfig: {

packages/cdk/lambda/utils/models.ts

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ const modelIds: ModelConfiguration[] = (
4141
.map((model) => ({
4242
modelId: model.modelId.trim(),
4343
region: model.region.trim(),
44-
...(model.inferenceProfileArn && {
45-
inferenceProfileArn: model.inferenceProfileArn,
46-
}),
4744
}))
4845
.filter((model) => model.modelId);
4946
// If there is a lightweight model among the available models, prioritize the lightweight model.
@@ -55,9 +52,6 @@ export const defaultModel: Model = {
5552
type: 'bedrock',
5653
modelId: defaultModelConfiguration.modelId,
5754
region: defaultModelConfiguration.region,
58-
...(defaultModelConfiguration.inferenceProfileArn && {
59-
inferenceProfileArn: defaultModelConfiguration.inferenceProfileArn,
60-
}),
6155
};
6256

6357
const imageGenerationModels: ModelConfiguration[] = (
@@ -69,19 +63,13 @@ const imageGenerationModels: ModelConfiguration[] = (
6963
(model: ModelConfiguration): ModelConfiguration => ({
7064
modelId: model.modelId.trim(),
7165
region: model.region.trim(),
72-
...(model.inferenceProfileArn && {
73-
inferenceProfileArn: model.inferenceProfileArn,
74-
}),
7566
})
7667
)
7768
.filter((model) => model.modelId);
7869
export const defaultImageGenerationModel: Model = {
7970
type: 'bedrock',
8071
modelId: imageGenerationModels?.[0]?.modelId ?? '',
8172
region: imageGenerationModels?.[0]?.region ?? '',
82-
...(imageGenerationModels?.[0]?.inferenceProfileArn && {
83-
inferenceProfileArn: imageGenerationModels[0].inferenceProfileArn,
84-
}),
8573
};
8674

8775
const videoGenerationModels: ModelConfiguration[] = (
@@ -93,19 +81,13 @@ const videoGenerationModels: ModelConfiguration[] = (
9381
(model: ModelConfiguration): ModelConfiguration => ({
9482
modelId: model.modelId.trim(),
9583
region: model.region.trim(),
96-
...(model.inferenceProfileArn && {
97-
inferenceProfileArn: model.inferenceProfileArn,
98-
}),
9984
})
10085
)
10186
.filter((model) => model.modelId);
10287
export const defaultVideoGenerationModel: Model = {
10388
type: 'bedrock',
10489
modelId: videoGenerationModels?.[0]?.modelId ?? '',
10590
region: videoGenerationModels?.[0]?.region ?? '',
106-
...(videoGenerationModels?.[0]?.inferenceProfileArn && {
107-
inferenceProfileArn: videoGenerationModels[0].inferenceProfileArn,
108-
}),
10991
};
11092

11193
// Model Params
@@ -420,27 +402,6 @@ const mergeConverseInferenceParams = (
420402
},
421403
}) as ConverseInferenceParams;
422404

423-
// Get inference profile ARN from modelId
424-
export const getInferenceProfileArn = (modelId: string): string | undefined => {
425-
const textModelConfig = modelIds.find((config) => config.modelId === modelId);
426-
if (textModelConfig?.inferenceProfileArn) {
427-
return textModelConfig.inferenceProfileArn;
428-
}
429-
const imageModelConfig = imageGenerationModels.find(
430-
(config) => config.modelId === modelId
431-
);
432-
if (imageModelConfig?.inferenceProfileArn) {
433-
return imageModelConfig.inferenceProfileArn;
434-
}
435-
const videoModelConfig = videoGenerationModels.find(
436-
(config) => config.modelId === modelId
437-
);
438-
if (videoModelConfig?.inferenceProfileArn) {
439-
return videoModelConfig.inferenceProfileArn;
440-
}
441-
return undefined;
442-
};
443-
444405
// API call, extract string from output, etc.
445406

446407
const createConverseCommandInput = (
@@ -539,9 +500,8 @@ const createConverseCommandInput = (
539500

540501
const guardrailConfig = createGuardrailConfig();
541502

542-
const modelIdOrArn = getInferenceProfileArn(model.modelId) || model.modelId;
543503
const converseCommandInput: ConverseCommandInput = {
544-
modelId: modelIdOrArn,
504+
modelId: model.modelId,
545505
messages: conversationWithCache,
546506
system: systemContextWithCache,
547507
inferenceConfig: params.inferenceConfig,

packages/cdk/lib/application-inference-profile-stack.ts

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)