Hexie
Hexie

Reputation: 4221

API Gateway not importing exported definition

I am testing my backup procedure for an API, in my API Gateway.

So, I am exporting my API from the API Console within my AWS account, I then go into API Gateway and create a new API - "import from swagger".

I paste my exported definition in and create, which throws tons of errors.

From my reading - it seems this is a known issue / pain.

I suspect the reason for the error(s) are because I use a custom authorizer;

"security" : [ {
      "TestAuthorizer" : [ ]
    }, {
      "api_key" : [ ]
    } ]

I use this on each method, hence, I get a lot of errors.

The weird thing is that I can clone this API perfectly fine, hence, I assumed that I could take an exported definition and re-import without issues.

Any ideas on how I can correct these errors (preferably within my API gateway, so that I can export / import with no issues).

An example of one of my GET methods using this authorizer is:

"/api/example" : {
  "get" : {
    "produces" : [ "application/json" ],
    "parameters" : [ {
      "name" : "Authorization",
      "in" : "header",
      "required" : true,
      "type" : "string"
    } ],
    "responses" : {
      "200" : {
        "description" : "200 response",
        "schema" : {
          "$ref" : "#/definitions/exampleModel"
        },
        "headers" : {
          "Access-Control-Allow-Origin" : {
            "type" : "string"
          }
        }
      }
    },
    "security" : [ {
      "TestAuthorizer" : [ ]
    }, {
      "api_key" : [ ]
    } ]
  }

Thanks in advance

UPDATE

The error(s) that I get when importing a definition I had just exported are: Your API was not imported due to errors in the Swagger file. Unable to put method 'GET' on resource at path '/api/v1/MethodName': Invalid authorizer ID specified. Setting the authorization type to CUSTOM or COGNITO_USER_POOLS requires a valid authorizer.

I get the message for each method in my API - so there is a lot.

Additionality, right at the end of the message, I get this: Additionally, these warnings were found: Unable to create authorizer from security definition: 'TestAuthorizer'. Extension x-amazon-apigateway-authorizer is required. Any methods with security: 'TestAuthorizer' will not be created. If this security definition is not a configured authorizer, remove the x-amazon-apigateway-authtype extension and it will be ignored.

I have tried with Ignoring the errors, same result.

Upvotes: 2

Views: 3204

Answers (2)

Hexie
Hexie

Reputation: 4221

For anyone that may come across this issue.

After LOTS of troubleshooting and eventually involving the AWS Support Team, this has been resolved and identified as an AWS CLI client bug (confirmed from AWS Support Team);

Final response.

Thank you for providing the details requested. After going through the AWS CLI version and error details, I can confirm the error is because of known issue with Powershell AWS CLI. I apologize for inconvenience caused due to the error. To get around the error I recommend going through the following steps

  1. Create a file named data.json in the current directory where the powershell command is to be executed

  2. Save the following contents to file {"extensions":"authorizers,integrations"}

  3. In Powershell console, ensure the current working directory is the same as the location where data.json is present

  4. Execute the following command aws apigateway get-export --parameters file://data.json --rest-api-id APIID --stage-name dev --export-type swagger C:\temp\export.json

Using this, finally resolved my issue - I look forward to the fix in one of the upcoming versions.

PS - this is currently on the latest version:

aws --version

aws-cli/1.11.44 Python/2.7.9 Windows/8 botocore/1.5.7

Upvotes: 1

vnasc
vnasc

Reputation: 21

Make sure you are exporting your swagger with both integrations and authorizers extensions.

Try exporting your swagger using AWS CLI:

aws apigateway get-export \
    --parameters '{"extensions":"integrations,authorizers"}' \
    --rest-api-id {api_id} \
    --stage-name {stage_name} \
    --export-type swagger swagger.json

The output will be sent to swagger.json file.

For more details about swagger custom extensions see this.

Upvotes: 2

Related Questions