Skip to content

v2.33.0

Latest

Choose a tag to compare

@github-actions github-actions released this 14 Apr 12:58
· 26 commits to refs/heads/main since this release
5765cc4

Summary

In this release, the HTTP event handler gains a new metrics middleware that lets you emit per-request latency, fault, and error metrics with a single line of configuration. The middleware automatically uses the matched route as a dimension and attaches request metadata like HTTP method, path, status code, and API Gateway request IDs.

We've also improved the parser package by exporting InferOutput from the public types entry point, resolving a TypeScript declaration emit error (TS2883) that affected consumers using safeParse mode — particularly those upgrading to TypeScript 6.

⭐ Congratulations to @yashar-new10 and @faberchri for their first PR merged in the project 🎉

Metrics Middleware

You can now use the Metrics utility with the HTTP event handler to automatically emit CloudWatch metrics for every request. The middleware:

  • Adds the matched route as a metric dimension (e.g., GET /users/:id)
  • Emits latency (Milliseconds), fault (Count), and error (Count) metrics
  • Attaches request metadata including httpMethod, path, statusCode, userAgent, and ipAddress
  • Adds API Gateway-specific metadata (apiGwRequestId, apiGwApiId) when available
  • Uses NOT_FOUND as the route dimension when no route matches, preventing dimension explosion
import { Router } from '@aws-lambda-powertools/event-handler/http';
import { metrics as metricsMiddleware } from '@aws-lambda-powertools/event-handler/http/middleware/metrics';
import { Metrics } from '@aws-lambda-powertools/metrics;
import type { Context } from 'aws-lambda';

const metrics = new Metrics({ namespace: 'my-app', serviceName: 'my-service' });
const app = new Router();

app.use(metricsMiddleware(metrics));

app.get('/users/:id', async ({ params }) => {
  return { id: params.id, name: 'Jane' };
});

export const handler = async (event: unknown, context: Context) =>
  app.resolve(event, context);

Changes

  • improv(parser): export InferOutput from public types entry point (#5175) by @yashar-new10
  • chore(deps): add esbuild as explicit devDependency (#5173) by @sdangol
  • chore: temporarily remove Bahrain (me-south-1) region from layer publishing (#5169) by @svozza
  • docs(commons): fix isStrictEqual and areArraysEqual JSDoc array comparison description (#5165) by @Zelys-DFKH
  • docs: fix dependencies & broken references (#5156) by @dreamorosi
  • docs: fix markdown table format (#5153) by @dothomson
  • style: remove useAwait linting rule (#5146) by @dreamorosi
  • docs(event-handler): update custom middleware example to use Store API (#5145) by @svozza
  • fix(commons): don't overwrite existing value with undefined in deepMerge (#5141) by @faberchri
  • fix(event-handler): http response body validation typings (#5125) by @nateiler
  • feat(event-handler): add metrics middleware for HTTP routes (#5086) by @svozza
  • fix: update middy types to be aligned with 7.1.2 update (#5100) by @willfarrell
  • fix(commons): rename AvailabilityZoneId to AvailabilityZoneID in docs and tests (#5118) by @svozza

🔧 Maintenance

This release was made possible by the following contributors:

@Zelys-DFKH, @dependabot[bot], @dothomson, @dreamorosi, @faberchri, @github-actions[bot], @nateiler, @sdangol, @svozza, @willfarrell, @yashar-new10, dependabot[bot] and github-actions[bot]