serverless/serverless · error · ServerlessError

MISSING_HTTP_API_METHOD

MISSING_HTTP_API_METHOD

Error message

Missing "method" property in function ${functionName} for httpApi event in serverless.yml

What it means

Thrown when an httpApi event has a non-wildcard path but no method. Every non-'*' route needs an HTTP method to form the routeKey ('METHOD path'). Without a method the route cannot be registered with API Gateway. The wildcard '*' path is the only one that does not require a method.

Source

Thrown at packages/serverless/lib/plugins/aws/package/compile/events/http-api.js:618

              path = '*'
            } else {
              ;[, method, path] = methodPath.match(methodPathPattern)
            }
          }
          path = String(path)
          let routeKey
          if (path === '*') {
            if (method && method !== '*') {
              throw new ServerlessError(
                `Invalid "path" property in function ${functionName} for httpApi event in serverless.yml`,
                'INVALID_HTTP_API_PATH',
              )
            }
            routeKey = '*'
            event.resolvedMethod = 'ANY'
          } else {
            if (!method) {
              throw new ServerlessError(
                `Missing "method" property in function ${functionName} for httpApi event in serverless.yml`,
                'MISSING_HTTP_API_METHOD',
              )
            }
            method = String(method).toUpperCase()
            if (method === '*') {
              method = 'ANY'
            } else if (!allowedMethods.has(method)) {
              throw new ServerlessError(
                `Invalid "method" property in function ${functionName} for httpApi event in serverless.yml`,
                'INVALID_HTTP_API_METHOD',
              )
            }
            event.resolvedMethod = method
            event.resolvedPath = path
            routeKey = `${method} ${path}`

            if (routes.has(routeKey)) {

View on GitHub (pinned to b9d7ea51c8)

Solutions

  1. Add method: GET (or POST/PUT/PATCH/DELETE/HEAD/OPTIONS/ANY) to the event.
  2. For string shorthand, use the 'METHOD /path' form exactly (e.g. 'GET /users').
  3. For a catch-all use path: '*' which needs no method.

Example fix

# before
functions:
  api:
    events:
      - httpApi:
          path: /users
# after
functions:
  api:
    events:
      - httpApi:
          method: GET
          path: /users
      # or shorthand
      - httpApi: 'GET /users'
Defensive patterns

Strategy: validation

Validate before calling

const ALLOWED = ['ANY','GET','POST','PUT','PATCH','OPTIONS','HEAD','DELETE']
cfg.functions && Object.entries(cfg.functions).forEach(([fn,f]) => (f.events||[]).forEach(e => {
  if (e.httpApi && typeof e.httpApi === 'object' && e.httpApi.path !== '*' && !e.httpApi.method) {
    throw new Error(`MISSING_HTTP_API_METHOD: fn ${fn} path ${e.httpApi.path} needs a method`)
  }
}))

Type guard

const hasMethodForConcretePath = (httpApi) =>
  httpApi?.path === '*' ||
  Boolean(httpApi?.method)

Prevention

When it happens

Trigger: An httpApi event object { path: '/users' } with no method, or a string shorthand that fails to match methodPathPattern (so method is undefined) and whose path is not '*'. The `if (!method)` branch fires.

Common situations: Omitting method in object form assuming a default. Malformed string shorthand that does not parse as 'METHOD /path'. Resolver/variable producing an empty method.

Related errors


AI-assisted analysis of serverless/serverless@b9d7ea51c8 (2026-08-13). Data as JSON: /api/errors/c354f5913b56a4b4. Report an issue: GitHub.