Bedrock Application inference profile

0

I have created a "application inference profile" for bedrock llm model in aws to track cost and usage, now i want to use that application inference model in lambda function. But the problem is with iam, that i need to attach bedrock:InvokeModel for both foundational and inference.

can anyone please suggest me to use only application inference only in lambda function?

asked 17 days ago126 views
1 Answer
0

To use an application inference profile in your Lambda function for Amazon Bedrock, you'll need to make a few adjustments to your IAM configuration and your Lambda code. Here's what you need to do:

  1. IAM Configuration: You're correct that you need the bedrock:InvokeModel permission. However, you don't need separate permissions for the foundational model and the inference profile. Instead, you should grant the Lambda function's execution role permission to use the application inference profile you've created.

    Add the following permissions to your Lambda function's IAM role:

    • bedrock:InvokeModel
    • bedrock:UseInferenceProfile

    The bedrock:UseInferenceProfile permission allows your Lambda function to use the application inference profile you've created.

  2. Lambda Function Code: In your Lambda function, when making the API call to Bedrock, you need to specify the inference profile. You can do this by including the Amazon Resource Name (ARN) or the ID of your application inference profile in the API request.

    When using the InvokeModel API, include the inferenceProfileArn or inferenceProfileId parameter in your request. For example:

    response = bedrock_runtime.invoke_model(
        modelId='your-model-id',
        inferenceProfileArn='arn:aws:bedrock:region:account-id:inference-profile/your-profile-id',
        body=your_request_body
    )

    By specifying the inference profile in your API call, you ensure that the model invocation is tracked and billed according to your application inference profile.

Remember, you only need to specify the application inference profile ARN or ID in your Lambda function. You don't need to directly reference the foundational model ARN, as the application inference profile already contains that information.

By following these steps, you can use your application inference profile in your Lambda function to track costs and usage for your Bedrock model invocations without directly referencing the foundational model.
Sources
Set up a model invocation resource using inference profiles - Amazon Bedrock
Use an inference profile in model invocation - Amazon Bedrock

profile picture
answered 17 days ago
  • { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "bedrock:InvokeModel", "bedrock:UseInferenceProfile"

    		],
    

    Error: Ln 8, Col 4 Invalid Action: The action bedrock:UseInferenceProfile does not exist.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions