Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions packages/cdk/lib/application-inference-profile-stack.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { Stack, StackProps, CfnOutput } from 'aws-cdk-lib';
import { Stack, StackProps, CfnOutput, ArnFormat } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import {
CfnApplicationInferenceProfile,
FoundationModel,
} from 'aws-cdk-lib/aws-bedrock';
import { CfnApplicationInferenceProfile } from 'aws-cdk-lib/aws-bedrock';
import { ProcessedStackInput } from './stack-input';

export interface ApplicationInferenceProfileStackProps extends StackProps {
Expand All @@ -25,31 +22,31 @@ export class ApplicationInferenceProfileStack extends Stack {
const createInferenceProfiles = (modelIds: typeof params.modelIds) => {
for (const modelId of modelIds) {
// Inference Profile is not supported Cross Region Inference
if (
modelId.region === currentRegion &&
!modelId.modelId.startsWith('us.') &&
!modelId.modelId.startsWith('apac.') &&
!modelId.modelId.startsWith('eu.') &&
!modelId.modelId.startsWith('global') &&
!modelId.modelId.startsWith('jp')
) {
if (modelId.region === currentRegion) {
const inferenceProfileNamePrefix = modelId.modelId
.replace(/\./g, '-')
.replace(/:/g, '-');
const model = FoundationModel.fromFoundationModelId(
this,
`FoundationModel${inferenceProfileNamePrefix}`,
{
modelId: modelId.modelId,
}
);
const isCrossRegionProfile =
modelId.modelId.startsWith('us.') ||
modelId.modelId.startsWith('apac.') ||
modelId.modelId.startsWith('eu.') ||
modelId.modelId.startsWith('global') ||
modelId.modelId.startsWith('jp');
const arn = Stack.of(this).formatArn({
service: 'bedrock',
resource: isCrossRegionProfile
? 'inference-profile'
: 'foundation-model',
resourceName: modelId.modelId,
arnFormat: ArnFormat.SLASH_RESOURCE_NAME,
});
const inferenceProfile = new CfnApplicationInferenceProfile(
this,
`ApplicationInferenceProfile${model.modelId}`,
`ApplicationInferenceProfile${modelId.modelId}`,
{
inferenceProfileName: `${inferenceProfileNamePrefix}${params.env}`,
modelSource: {
copyFrom: model.modelArn,
copyFrom: arn,
},
}
);
Expand Down