aws-samples / aws-samples/bedrock-chat
[Feature Request] Precise cost calculation - /admin/shared-bot-analytics
- Dominant language
- TypeScript
- Stars
- 1.3k
- Forks
- 535
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 10
Description
## Describe the solution you'd like
1. tldr - it uses the local timezone where the backend is deployed, in our case is us-east-1 (N. Virginia / Eastern Daylight Time / GMT+4), which is very confusing for the users. They 100% don't care about the timezone, and expect it to just work for their timezone. Current implementation still works to grab the tendency of the usage, but it cannot reflect the actual usage.
2. Long technical explanation - when a user uses a chatbot, their conversation log is stored in DynamoDB, along with their timestamp, and also the price estimation for that particular conversation (calculated using the method above). Both are calculated by [Python 3.11](https://github.com/aws-samples/bedrock-claude-chat/blob/df07eb7928e63060c615e81596aa9e951c5bdc4b/backend/Dockerfile#L1) ([get_current_time](https://github.com/aws-samples/bedrock-claude-chat/blob/df07eb7928e63060c615e81596aa9e951c5bdc4b/backend/app/utils.py#L36), and [calculate_price](https://github.com/aws-samples/bedrock-claude-chat/blob/df07eb7928e63060c615e81596aa9e951c5bdc4b/backend/app/bedrock.py#L153)). Python 3.11 [uses local timezone by default](https://docs.python.org/3.11/library/datetime.html#datetime.datetime.now), if parameters are not specified (like in our case). They then [exported the DynamoDB table to an S3 bucket](https://github.com/aws-samples/bedrock-claude-chat/blob/main/backend/s3_exporter/index.py). The export job is done [hourly](https://github.com/aws-samples/bedrock-claude-chat/blob/df07eb7928e63060c615e81596aa9e951c5bdc4b/backend/s3_exporter/index.py#L40) by a combination of [EventBridge + Lambda function](https://github.com/aws-samples/bedrock-claude-chat/blob/main/backend/s3_exporter/index.py). In the pricing estimation page, they use Athena to [query the conversation log](https://github.com/aws-samples/bedrock-claude-chat/blob/df07eb7928e63060c615e81596aa9e951c5bdc4b/backend/app/repositories/usage_analysis.py#L126), and display them to the user.
## Why the solution needed
To show precise usage for administrators.
## Implementation feasibility
Are you willing to discuss the solution with us, decide on the approach, and assist with the implementation?
- [ ] Yes
- [ ] No
Contributor guide
Research direction
Start with backend/app/utils.py#get_current_time and backend/app/bedrock.py#calculate_price to understand how timestamps and estimates are produced, then trace backend/s3_exporter/index.py and backend/app/repositories/usage_analysis.py. Check how the hourly export and Athena query use those values. Done means the administrator analytics page reports usage and cost without relying on the backend deployment timezone.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python
- Domain
- analytics, backend, cloud, databases
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100