Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

372
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!