Skip to content

Types AwsEvent and APIGatewayProxyEvent are not compatible #2939

Description

@dennis-grunert

@slack/bolt version

4.7.2

Your App and Receiver Configuration

const awsLambdaReceiver = new AwsLambdaReceiver({
    signingSecret: SLACK_SIGNING_SECRET,
})
const app = new App({
    token: process.env.SLACK_BOT_TOKEN,
    receiver: awsLambdaReceiver,
})

Node.js runtime version

v22.22.2

Steps to reproduce:

  1. Create a Lambda proxy integration in AWS API Gateway with the payload version v1 (e.g., with the CDK construct LambdaRestApi).
  2. Create a handler in TypeScript with
import type { APIGatewayProxyEvent, APIGatewayProxyResult, Callback, Context } from "aws-lambda"

export const handler = async (
    event: APIGatewayProxyEvent,
    context: Context,
    callback: Callback,
): Promise<APIGatewayProxyResult> => {
    console.log(event)
    
    const boltHandler = await awsLambdaReceiver.start()
    return await boltHandler(event, context, callback)
}
  1. Confirm that the console.log returns an event with multiValueQueryStringParameters: null.

Expected result:

No type errors.

Actual result:

There is a type mismatch when calling boltHandler. It expects as first argument AwsEvent = AwsEventV1 | AwsEventV2 (in our case, only AwsEventV1 is relevant). But the handler actually receives APIGatewayProxyEvent.

APIGatewayProxyEvent is the correct type to use since it allows null for multiValueQueryStringParameters, which is what the handler is called with (confirmed via the console.log above).

The only difference between AwsEventV1 and APIGatewayProxyEvent (defined here) is that AwsEventV1 does not allow multiValueQueryStringParameters to be null while APIGatewayProxyEvent does.

See also #2277, where the type mismatch was probably introduced.

Workaround

Cast to AwsEventV1:

return await boltHandler(event as AwsEventV1, context, callback)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions