Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

369
Vistas
Typescript for AWS HTTP API Gateway Lambda Handlers

Currently I use the following to type the lambda functions for RestApi:

import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
export const handler = async (event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> => {}

This doesn't correctly work with the new AWS Gateway HTTP API, where the HTTP method can be fetched using event.requestContext.http.method.

Are there other types that I should use?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Are there other types that I should use?

I do not think so. The types are available via DefinitelyTyped. [1] Looking through some of the issues regarding the "aws-lambda" types, you will notice that the API Gateway types are not updated frequently. [2]

Furthermore, the payload format version changed for API Gateway, see [3]:

The payload format version specifies the format of the data that API Gateway sends to a Lambda integration, and how API Gateway interprets the response from Lambda. If you don't specify a payload format version, the AWS Management Console uses the latest version by default. If you create a Lambda integration by using the AWS CLI, AWS CloudFormation, or an SDK, you must specify a payloadFormatVersion. The supported values are 1.0 and 2.0.

I guess you are using the latest version which is 2.0. Version 2.0 provides the HTTP method as property requestContext.http.method.

Version 1.0 provides the HTTP method as property requestContext.httpMethod.

Solution

You can either 1.) write typings for the new payload format version and submit them to DefinitelyTyped via PR for package "@types/aws-lambda" or 2.) set your API Gateway to use version 1.0.

Honestly, I do not know if using the payload version 1.0 is possible for HTTP APIs. Maybe AWS is enforcing the latest version on the new APIs since there is no need to support the older format.

References

[1] https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/aws-lambda/trigger/api-gateway-proxy.d.ts
[2] https://github.com/DefinitelyTyped/DefinitelyTyped/issues/38720#issuecomment-586051966
[3] https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html

over 4 years ago · Santiago Trujillo Denunciar

0

The accepted answer is out of date. aws-lambda now exports APIGatewayProxyEventV2 as well:

import { APIGatewayProxyEventV2 } from 'aws-lambda'
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda