How to create a $default route with AWS httpApi?

Hello,

I’m using Serverless Framework v2.56.0 with @serverless/typescript. I’ve created a serverless.ts file that includes a “default” function as per the AWS Guide on API Gateway: Working with routes for HTTP APIs - Amazon API Gateway

The path in this example should just be $default, however it looks like when the serverless framework builds the cloudformation stack, it’s prepending a leading slash to ALL paths, so it becomes /$default, which is then reported as invalid when deploying the stack:

An error occurred: HttpApiRouteGetdefault - The provided route key is not formatted properly for HTTP protocol. Format should be "[HTTP METHOD] /[RESOURCE PATH]" or "$default" (Service: AmazonApiGatewayV2; Status Code: 400; Error Code: BadRequestException

Is there any way to create a default function with Serverless Framework and API Gateway?

Hi,

Did you ever find a solution to this? I’m seeing the same error when trying to deploy to API Gateway.

Mark

Yea, with the latest version of @serverless/typescript the syntax for a “Default Handler” is just:

{ httpApi: '*' }
1 Like