monitor Bedrock model charge per invocation resource

0

Hi,

Is there any way to monitor the cost of Bedrock invocations per invocation resource? I.e. if I have several Lambdas that call Bedrock, I want to know how much Bedrock costs for each one of them. Thanks

3 Answers
3

Hello,

To monitor the cost of Bedrock invocations per invocation resource with precision and efficiency, follow these expert recommendations:

1.Granular Tagging Strategy: Implement a meticulous tagging strategy for your Bedrock resources. Tag each Lambda function that invokes Bedrock with unique identifiers, such as "Bedrock-Function" or "Service-Name".

2.Custom Cost Allocation Tags: Leverage AWS Cost Allocation Tags to associate costs with specific resources based on the tags you've assigned. Create custom cost allocation tags that align with the tags used to label your Bedrock-invoking Lambda functions.

3.Cost Analysis with AWS Cost Explorer: Utilize AWS Cost Explorer, a powerful tool for in-depth cost analysis. Filter and segment your costs based on the custom tags you've applied to your resources, allowing you to isolate and examine the costs incurred by each Bedrock-invoking Lambda function.

4.Continuous Monitoring and Alerting: Establish proactive cost monitoring mechanisms using AWS Cost Explorer. Set up budget alerts or notifications to receive real-time alerts when the costs associated with Bedrock invocations exceed predefined thresholds. This proactive approach ensures timely awareness of any cost anomalies or overruns.

By implementing these strategies, you'll have a robust system in place to effectively monitor the cost of Bedrock invocations per invocation resource, empowering you to optimize your AWS spending and resource utilization with expert precision.

profile picture
answered 21 days ago
0

Hi chedva,

please follow below steps to reslove your issue.

Enable Cost Allocation Tags:

  • Go to the AWS Billing console.
  • Navigate to Cost Allocation Tags.
  • Activate the tags you’ve assigned to your Lambda functions.

Tag Your Lambda Functions:

  • In the AWS Management Console, go to the Lambda service.
  • Select your Lambda function.
  • Under the Tags section, add tags such as Key: Service, Value: BedrockCaller1 (you can create your own keys and values).

Set Up CloudWatch Logs for Lambda:

  • Ensure your Lambda function is logging to CloudWatch.
  • You can add logging statements in your Lambda code to log when it invokes Bedrock.

Use AWS X-Ray for Tracing:

  • Enable AWS X-Ray for your Lambda functions. This will give you detailed traces of the requests, including downstream service calls to Bedrock.
  • In the Lambda console, under Monitoring and operations tools, enable X-Ray.

Create an Athena Table for Cost and Usage Reports:

  • Go to the AWS Cost and Usage Reports page in the Billing console.
  • Create and configure a new Cost and Usage Report to be delivered to an S3 bucket.
  • Use Amazon Athena to query the data:
    • Create a new database in Athena.
    • Create a new table pointing to the S3 bucket where your CUR files are stored.
  • Example query to filter costs by Lambda tags:
 SELECT
  line_item_resource_id,
  product_servicecode,
  SUM(line_item_blended_cost) as total_cost
FROM
  cost_and_usage_report
WHERE
  line_item_usage_start_date >= '2024-05-01T00:00:00Z'
  AND line_item_usage_end_date <= '2024-05-31T23:59:59Z'
  AND resource_tags_service = 'BedrockCaller1'
GROUP BY
  line_item_resource_id,
  product_servicecode
ORDER BY
  total_cost DESC;
answered 21 days ago
0

Hi,

There is a reat-time and 100% precise mechanism to monitor the costs of of Bedrock queries that I constantly use: the headers that are returned as http headers by Bedrock in response to each query.

They have the following names:

1. x-amzn-bedrock-input-token-count
2. x-amzn-bedrock-output-token-count
3. x-amzn-bedrock-invocation-latency

They look like this:

{
   "Date":"Fri, 02 Feb 2024 12:44:00 GMT",
   "Content-Type":"application/json",
   "Content-Length":"1419",
   "Connection":"keep-alive",
   "x-amzn-RequestId":"3abacd58-8693-4a25-b1c0-e80ab9efb812",
   "X-Amzn-Bedrock-Invocation-Latency":"14244",
   "X-Amzn-Bedrock-Output-Token-Count":"300",
   "X-Amzn-Bedrock-Input-Token-Count":"13"
}

In your case, you don't care for the invocation latency. But, if you use the 2 others (with our preferred AWS SDK language) with corresponding price per 1'000 token given on Bedrock pricing page, you will know exactly how much each query / response cost you. See on-demand pricing on https://aws.amazon.com/bedrock/pricing/

Best,

Didier

profile pictureAWS
EXPERT
answered 21 days ago

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