← All IntegrationsIntegration

Analytics for AWS

Teams on AWS run web apps, CLI tools, and APIs across dozens of services. BetterMeter gives you a single analytics layer across all of them — CloudFront for first-party web tracking, the Node SDK for Lambda functions and ECS services, and the CLI for pipeline reporting.

CloudFront behavior for first-party proxy

Add a CloudFront cache behavior that routes /bm/* requests to BetterMeter as an additional origin. Three paths have to travel through it — the tracker script, the event endpoint and the noscript pixel — because the script on its own collects nothing.

CloudFront Additional Origin + Behavior
Origin:
  Domain: bettermeter.com
  Protocol: HTTPS only
  Origin Path: (empty — the function below sets the path)

Cache Behavior:
  Path Pattern: /bm/*
  Origin: bettermeter.com
  Viewer Protocol: HTTPS only
  Allowed Methods: GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE
  Cache Policy: CachingDisabled
  Origin Request Policy: AllViewerExceptHostHeader
  Function Association: Viewer request -> bm-proxy

CloudFront forwards the viewer's URI to the origin unchanged, so /bm/s would arrive at BetterMeter as /bm/s and 404. A CloudFront Function on the viewer request maps the three paths across:

CloudFront Function: bm-proxy
var PATHS = {
  "/bm/s": "/api/s",
  "/bm/e": "/api/e",
  "/bm/p": "/api/p",
};

function handler(event) {
  var request = event.request;
  var mapped = PATHS[request.uri];

  if (mapped) {
    request.uri = mapped;
  }

  return request;
}

Then serve the snippet from your own domain. data-api is required: without it the tracker derives its endpoint from the script's origin and posts events to /api/e on your distribution, which no behavior matches. The install looks healthy and records nothing.

Proxied snippet
<script defer data-site="your-domain.com" data-api="/bm/e" src="/bm/s"></script>
<img src="/bm/p?s=your-domain.com" alt="" style="position:absolute;width:0;height:0;overflow:hidden" />

Track Lambda functions and API Gateway

Use the @bettermeter/node SDK inside Lambda functions to track API endpoint usage. The SDK batches events efficiently to minimize Lambda execution time.

Lambda handler with BetterMeter
import { BetterMeter } from "@bettermeter/node";

const bm = new BetterMeter({
  siteId: "my-api",
  apiKey: process.env.BETTERMETER_API_KEY,
});

export const handler = async (event) => {
  await bm.trackApi({
    method: event.httpMethod,
    path: event.path,
    statusCode: 200,
  });

  return { statusCode: 200, body: JSON.stringify({ ok: true }) };
};

Unified view across AWS services

  • 01S3 + CloudFront static sites — Add the tracker script tag. CloudFront proxy keeps it first-party.
  • 02ECS / Fargate APIs — Use the Node SDK's Express middleware for automatic route tracking.
  • 03Lambda@Edge — Inject the tracker script at the edge for server-rendered pages.
  • 04CodePipeline / CodeBuild — Run the BetterMeter CLI in build steps for automated reporting.
CloudFront Proxy
First-party at the edge
Lambda SDK
API tracking
Unified Dashboard
Web + API + CLI