by

Bare-bones Swagger Example for API Gateway Simplified Proxy Features

Amazon API Gateway just made it a LOT easier to build an API to front an existing HTTP backend or Lambda functions.

Recent additions of a few simple but powerful new features reduce the amount of configuration needed to build an API Gateway proxy by several times. No more mapping templates, parameter mapping, response mappings, etc. (unless you need them).

Here’s a super simple example demonstrating the 3 new features (greedy path parameter, “ANY” method, and proxy integration types).

This API will accept requests using any HTTP method to any subpath of any depth under either /http or /lambda. Any request under /http will proxy all headers, path parameters, and query string parameters to the HTTP integration (httpbin.org). Any request under /lambda will invoke a Lambda function with complete API request data in accordance with the proxy convention defined here.

---
swagger: "2.0"
info:
  version: "2016-09-23T22:23:23Z"
  title: "Simple Proxy Example - Ryan Green"
host: "zte3bswjjb.execute-api.us-east-1.amazonaws.com"
basePath: "/demo"
schemes:
- "https"
paths:
  /http/{proxy+}:
    x-amazon-apigateway-any-method:
      parameters:
      - name: "proxy"
        in: "path"
      x-amazon-apigateway-integration:
        type: "http_proxy"
        uri: "http://httpbin.org/{proxy}"
        httpMethod: "ANY"
        passthroughBehavior: "when_no_match"
        requestParameters:
          integration.request.path.proxy: "method.request.path.proxy"
  /lambda/{proxy+}:
    x-amazon-apigateway-any-method:
      parameters:
      - name: "proxy"
        in: "path"
      responses: {}
      x-amazon-apigateway-integration:
        type: "aws_proxy"
        uri: "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:[MY_ACCOUNT_ID]]:function:[MY_FUNCTION_NAME]]/invocations"
        passthroughBehavior: "when_no_match"
        httpMethod: "POST"

Write a Comment

Comment