Skip to content

Daily Metrics Aggregation Lambda #103

@saquibb8

Description

@saquibb8

User Story

As a system, I want an EventBridge-scheduled Lambda function to aggregate platform metrics daily and store them in S3, so that an always up-to-date snapshot of key stats is available for the application to consume.


Background

The Saayam homepage displays four key metrics — Total Requests, Requests Resolved, Total Volunteers, and Total Beneficiaries. Currently these show as 0. These numbers need to be computed from Aurora/Postgres and made available to the frontend in a performant, scalable way without direct database access from the client.


Objective

Build a Python-based AWS Lambda function triggered daily by EventBridge that queries Aurora/Postgres, aggregates the four homepage metrics, and writes the result as a JSON file to a designated S3 bucket.


Scope

  • Create an EventBridge cron rule to trigger the Lambda once daily
  • Lambda queries Aurora/Postgres for the four metric counts
  • Lambda writes the result to s3://saayam-public-metrics/homepage/metrics.json
  • JSON schema to be documented and shared with the web app team
  • Error handling and logging via CloudWatch

Acceptance Criteria

  • EventBridge triggers the Lambda on schedule daily
  • Lambda successfully connects to Aurora and returns correct counts
  • metrics.json is written to the correct S3 path after each run
  • JSON follows the agreed schema:
    {
      "totalRequests": 120,
      "requestsResolved": 80,
      "totalVolunteers": 45,
      "totalBeneficiaries": 60
    }
  • CloudWatch logs confirm successful execution or capture errors
  • Schema is documented and handed off to the web app team

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions