Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bedrock): add cross region inference profiles #31958

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jdebuseamazon
Copy link
Contributor

Issue # (if applicable)

Closes #31957

Reason for this change

Abstractions for Bedrock cross region inference profiles and their identifiers (see), similar to those for Bedrock foundation models (see), do not currently exist; these would be useful for granting invoke permissions.

Description of changes

Added

  • CrossRegionInferenceProfileIdentifier class containing cross region inference profile identifiers
  • CrossRegionInferenceProfile class containing
    • cross region inference profile identifiers along with their associated foundation model identifiers and supported regions
    • a method to grant a principal permission to invoke the inference profile and associated foundation model within a region

Description of how you validated changes

Unit tests and an integration test.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added feature-request A feature should be added or improved. p2 labels Oct 31, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team October 31, 2024 12:43
@github-actions github-actions bot added the beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK label Oct 31, 2024
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 52a175c
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Oct 31, 2024
This was referenced Nov 1, 2024
@pahud
Copy link
Contributor

pahud commented Nov 16, 2024

I was thinking if it's possible we can have a InferenceProfile class with a fromFoundationModel() method that would return a class with inference profile arn?

For example,

claud 3.5 sonnet v2

  • model ID - us.anthropic.claude-3-5-sonnet-20241022-v2:0
  • inference profile arn - arn:aws:bedrock::<ACCOUNT_ID>:inference-profile/us.anthropic.claude-3-5-sonnet-20241022-v2:0

I was considering a class like this

export interface IInferenceProfile {
  profileArn: string;
}

export class InferenceProfile implements IInferenceProfile {
  readonly profileArn: string;

  private static getCountryCode(scope: Construct): string {
    const stack = Stack.of(scope);
    if (!Token.isUnresolved(stack.region)) {
      return stack.region.startsWith('us') ? 'us' : 'eu';
    }
    return 'us';
  }

  static fromModel(scope: Construct, model: bedrock.FoundationModelIdentifier): IInferenceProfile {
    // Construct the inference profile ARN dynamically
    const profileArn = Stack.of(scope).formatArn({
      service: 'bedrock',
      resource: 'inference-profile',
      resourceName: `${this.getCountryCode(scope)}.${model.modelId}`,
    });
    return new InferenceProfile(profileArn);
  }

  static fromInferenceProfileArn(arn: string): IInferenceProfile {
    return new InferenceProfile(arn);
  }
  
  constructor(profileArn: string) {
    this.profileArn = profileArn;
  }
}

So we can bulid up the inference profile for Claude 3.5 Sonnet v2 like this

// Create an inference profile for the model
const inferenceProfile = InferenceProfile.fromModel(this, bedrock.FoundationModelIdentifier.ANTHROPIC_CLAUDE_3_5_SONNET_20241022_V2_0);

Things we need to check:

  • Not all foundationModels have their inference profiles, we probably need to maintain a support list in the InferenceProfile class?
  • other considerations?

@jdebuseamazon
Copy link
Contributor Author

Thanks for the suggestions @pahud, I think that'd be a good way to proceed and I'll take a closer look in the coming weeks

@krokoko
Copy link

krokoko commented Nov 20, 2024

We are adding support for it also in awslabs/generative-ai-cdk-constructs#800 for the L2 Bedrock construct, which we expect to merge back to the core cdk

@aws-cdk-automation
Copy link
Collaborator

This PR has been in the MERGE CONFLICTS state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK feature-request A feature should be added or improved. p2 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bedrock: Cross Region Inference Constructs
4 participants