1
votes

FYI - I've checked similar issues related to this, but none solves my problem.

I'm trying to create the Swagger definition for a number of APIs under AWS Api-Gateway. I'm able to successfully do this for other(POST, GET) endpoints from an auto-generated YAML configuration I downloaded from the API Stage.

But I encountered issues when I tried to do same for an Api-Gateway endpoint with Lambda Proxy Integration: Error from Swagger editor.swagger.io

Below is my YAML definition for the failing endpoint:

    swagger: "2.0"
    info:
      version: "2018-04-18T17-09-07Z"
      title: "XXX API"
    host: "api.xxx.io"
    schemes:
    - "https"
    parameters:
      stage:
        name: stage
        in: path
        type: string
        enum: [ staging, production]    
        required: true
    paths:
      /env/{stage}/{proxy+}:
        x-amazon-apigateway-any-method:
          produces:
            - "application/json"
          parameters:
            - $ref: '#/parameters/stage'
            - name: "proxy"
              in: "path"
              required: true
              type: "string"
          responses: {}
          x-amazon-apigateway-integration:
            uri: "arn:aws:apigateway:eu-central-1:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-central-1:xxxxxxxxx:function:environment/invocations"
            responses:
              default:
                statusCode: "200"
            passthroughBehavior: "when_no_match"
            httpMethod: "POST"
            cacheNamespace: "4vbcjm"
            cacheKeyParameters:
              - "method.request.path.proxy"
            contentHandling: "CONVERT_TO_TEXT"
            type: "aws_proxy"

this is inline with AWS Documentation: enter link description here

Please, what am I missing?

1

1 Answers

0
votes

At a glance I believe you have an error in your parameters block. If you include a $ref it discards anything in that block that follows it, so your proxy name is getting dropped. I have a similar setup with api-gateway proxying all calls to a lambda and this is my parameters block:

parameters:
- name: "proxy"
  in: "path"
  required: true
  type: "string"

Additionally you may want an authorizer if you're at all worried about DDoS or serving up secure data. That's done by adding a security array as a sibling to parameters, and a securityDefinitions block as a sibling to paths

security:
- authorizer: []

securityDefinitions:
  authorizer:
    type : "apiKey"
    name : "Authorization"
    in : "header"
    x-amazon-apigateway-authtype : "custom"
    x-amazon-apigateway-authorizer : {
      type : "request",
      authorizerUri : "arn:aws:apigateway:${region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${region}:${account_id}:function:${authorizer_function_name}/invocations",
      authorizerResultTtlInSeconds : 58,
      identitySource: "method.request.header.authorization",
    }

*note I'm publishing swagger as a terraform template, hence the ${} substitution.