- Newest
- Most votes
- Most comments
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:
-
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. -
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 theinferenceProfileArn
orinferenceProfileId
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
Relevant content
- asked 5 months ago
- AWS OFFICIALUpdated 10 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.