Dave Konopka

Forgot about Amazon API Gateway models

Let's work together!

Are you hiring for remote site reliability engineering or infrastructure automation positions? Here's my resume. Let's talk.

I'm also available for DevOps project work. Are you fighting fires instead of serving your customers? Hire me to identify the roadblocks and make improvements so you can get back to focusing on your customers.

In my post on building a serverless URL shortener I neglected to mention API Gateway models at all.

A model defines a JSON schema for data passed in or out of API methods. Models are assigned to method requests/responses. They play a role in data transformations that happen within mapping templates. Models are not used for validating input data. That seems like a logical use for them so perhaps they will serve this role in the future.

It’s easy to forget about API Gateway models. You can stage a functioning API without creating any models contrary to misleading web panel error messages (more on this below). Also, Swagger API exports don’t seem to include any sign of models you do create. That’s why if you import the Swagger definition included with the serverless URL shortener repo you’ll get a misleading popup error message in the AWS web panel:

You need to define a Model to select before adding a status code output. You can define models on the Models page.

I’ve been able to stage API’s without a model despite this error message. You can get rid of the error though by creating a model. Within the API, click Resources -> Model. Add a model named “Token”.

API Gateway model panel

Add the following schema which defines an object with url and token properties.

  "$schema": "http://json-schema.org/draft-04/schema#",
  "id": "http://jsonschema.net",
  "type": "object",
  "properties": {
    "url": {
      "id": "http://jsonschema.net/url",
      "type": "string"
    "token": {
      "id": "http://jsonschema.net/token",
      "type": "string"
  "required": [