Skip to content

v2.29.0

Latest

Choose a tag to compare

@github-actions github-actions released this 21 Nov 20:02
· 19 commits to refs/heads/main since this release
fa726e0

Summary

🎉 Powertools for AWS Lambda (Typescript) - Event Handler Utility is now Generally Available (GA)

Docs

We're excited to announce that the Event Handler utility is now production-ready! 🚀
Event Handler provides lightweight routing to reduce boilerplate for API Gateway REST/HTTP API, ALB and Lambda Function URLs.

⭐ Congratulations to @yoshi-taka, @iamgerg, @fidelisojeah, and @benthorner for their first PR merged in the project 🎉

Import path update

With Event Handler moving to GA, the import path has changed from the experimental namespace to a stable one.

// Before
import { Router } from '@aws-lambda-powertools/event-handler/experimental-rest';

// Now
import { Router } from '@aws-lambda-powertools/event-handler/http';

Support for HTTP APIs, ALB, and Function URL

Event Handler now supports HTTP APIs (API Gateway v2), Application Load Balancers (ALB) and Lambda Function URL in addition to the existing REST API and support. This means you can use the same routing API across different AWS services, making it easier to build and migrate serverless applications regardless of your chosen architecture.

import { Router } from '@aws-lambda-powertools/event-handler/http';
import type {
  ALBEvent,
  APIGatewayProxyEvent,
  APIGatewayProxyEventV2,
  Context,
  LambdaFunctionURLEvent,
} from 'aws-lambda';

const app = new Router();
app.get('/hello', () => {
  return {
    message: 'Hello Event Handler!',
  };
});

// Works across different services without any changes 
export const restApiHandler = (event: APIGatewayProxyEvent, context: Context) =>
  app.resolve(event, context);

export const httpApiHandler = (
  event: APIGatewayProxyEventV2,
  context: Context
) => app.resolve(event, context);

export const albHandler = (event: ALBEvent, context: Context) =>
  app.resolve(event, context);

export const lambdaFunctionUrlHandler = (
  event: LambdaFunctionURLEvent,
  context: Context
) => app.resolve(event, context);

Response Streaming

You can now stream responses directly from your Lambda functions, enabling use cases like serving large files, real-time data feeds, or progressive rendering. You just need to wrap your Router with streamify and you’re good to go.

import {
  Router,
  streamify,
} from '@aws-lambda-powertools/event-handler/http';

const app = new Router();

app.get('/video-stream', async (reqCtx) => {
  reqCtx.res.headers.set('content-type', 'video/mp4');
  return createVideoStream();
});

app.get('/hello', () => {
  return { message: 'Hello World' };
});

export const handler = streamify(app);

Binary Response

Event Handler now also includes first-class support for binary responses, making it straightforward to serve images, PDFs, or any other binary content from your Lambda functions. The utility handles the necessary encoding and content-type headers automatically.

import { createReadStream } from 'node:fs';
import { Router } from '@aws-lambda-powertools/event-handler/http';
import type { Context } from 'aws-lambda';

const app = new Router();

app.get('/logo', async (reqCtx) => {
  reqCtx.res.headers.set('Content-Type', 'image/png');
  return createReadStream(`${process.env.LAMBDA_TASK_ROOT}/logo.png`);
});

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

Changes

  • feat(parser): add type for values parsed by DynamoDBStreamRecord (#4793) by @benthorner
  • fix(event-handler): moved the response mutation logic to the composeMiddleware function (#4773) by @sdangol
  • feat(event-handler): add support for ALB (#4759) by @svozza
  • test(maintenance): Expose ResponseStream object to simplify testing in event handler (#4753) by @svozza
  • fix(event-handler): handle repeated queryString values (#4755) by @dreamorosi
  • test(maintenance): remove unnecessary esbuild banner from e2e tests (#4745) by @svozza
  • feat(event-handler): expose response streaming in public API (#4743) by @svozza
  • fix(logger): infinite loop on log buffer when item size is max bytes (#4741) by @fidelisojeah
  • fix(logger): not passing persistent keys to children (#4740) by @iamgerg
  • fix(event-handler): allow event handler response to return array (#4725) by @arnabrahman
  • feat(event-handler): add first-class support for binary responses (#4723) by @svozza
  • feat(event-handler): Add support for HTTP APIs (API Gateway v2) (#4714) by @svozza
  • chore(event-handler): unflag http handler from experimental (#4801) by @svozza
  • feat(batch): use async local storage for batch processing (#4700) by @svozza
  • feat(logger): use async local storage for logger (#4668) by @svozza
  • feat(metrics): use async local storage for metrics (#4663) (#4694) by @svozza
  • improv(commons): Make trace ID access more robust (#4693) by @svozza

📜 Documentation updates

🔧 Maintenance

This release was made possible by the following contributors:

@arnabrahman, @benthorner, @dependabot[bot], @dreamorosi, @fidelisojeah, @github-actions[bot], @iamgerg, @kawaaaas, @sdangol, @svozza, @yoshi-taka, dependabot[bot] and github-actions[bot]