-
Notifications
You must be signed in to change notification settings - Fork 79
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
ai models support cross-region inference profile #3076
Comments
Hey,👋 thanks for raising this! I'm going to transfer this over to our API repository for better assistance 🙂 |
Hey @zxkane, thanks for raising the issue! Regarding the cross-region inference profile, please take a look at the followup of a similar issue: AI kit does not support Cross-region inference #8121. It provides an example of how to implement within Amplify backend. Feel free to ask if you have more concerns. Thanks. |
Thanks for sharing the workaround, it's not trivial to grant additional IAM permissions to the role. Also, it requires additional logic to support environment-agnostic deployment in multiple regions. So it would be useful as a built-in feature to mitigate the capacity limitation of those models. |
Hey @zxkane. Thanks for sharing feedbacks and concerns. We will surely have your concerns discussed and reviewed, and evaluated whether this should be categorized as a feature request. Meanwhile, will have the topic updated here once the next step is confirmed. |
Agreed, it also requires figuring out which IAM permissions are needed in the Amazon Bedrock documentation. We want to offer a more seamless experience for setting up cross-region inference with AI kit. Thanks for the feature request! We'll update this issue with any news. |
Below is a code snippet of how to hack both function createBedrockPolicyStatement(currentRegion: string, accountId: string, modelId: string, crossRegionModel: string) {
return new PolicyStatement({
resources: [
`arn:aws:bedrock:*::foundation-model/${modelId}`,
`arn:aws:bedrock:${currentRegion}:${accountId}:inference-profile/${crossRegionModel}`,
],
actions: ['bedrock:InvokeModel*'],
});
}
if (CROSS_REGION_INFERENCE && CUSTOM_MODEL_ID) {
const currentRegion = getCurrentRegion(backend.stack);
const crossRegionModel = getCrossRegionModelId(currentRegion, CUSTOM_MODEL_ID);
// [chat converstation]
const chatStack = backend.data.resources.nestedStacks?.['ChatConversationDirectiveLambdaStack'];
if (chatStack) {
const conversationFunc = chatStack.node.findAll()
.find(child => child.node.id === 'conversationHandlerFunction') as IFunction;
if (conversationFunc) {
conversationFunc.addToRolePolicy(
createBedrockPolicyStatement(currentRegion, backend.stack.account, CUSTOM_MODEL_ID, crossRegionModel)
);
}
}
// [insights generation]
const insightsStack = backend.data.resources.nestedStacks?.['GenerationBedrockDataSourceGenerateInsightsStack'];
if (insightsStack) {
const dataSourceRole = insightsStack.node.findChild('GenerationBedrockDataSourceGenerateInsightsIAMRole') as IRole;
if (dataSourceRole) {
dataSourceRole.attachInlinePolicy(
new Policy(insightsStack, 'CrossRegionInferencePolicy', {
statements: [
createBedrockPolicyStatement(currentRegion, backend.stack.account, CUSTOM_MODEL_ID, crossRegionModel)
],
}),
);
}
}
} I don't think it's an easy thing for the full-stack developers without strong CDK knowledge. |
Environment information
Describe the feature
Cross-region inference enhances the resilience of Bedrock invocation.
https://docs.aws.amazon.com/bedrock/latest/userguide/cross-region-inference.html
Use case
invoke the LLM models of Bedrock which support cross-region inference
The text was updated successfully, but these errors were encountered: