API 网关不导入导出的定义
API Gateway not importing exported definition
我正在 API Gateway
.
中测试 API 的备份程序
所以,我从我的 AWS 账户中的 API Console
导出我的 API,然后我进入 API Gateway
并创建一个新的 API - "import from swagger".
我粘贴导出的定义并创建,这会引发大量错误。
根据我的阅读 - 这似乎是一个已知问题/痛苦。
我怀疑错误的原因是因为我使用了自定义授权方;
"security" : [ {
"TestAuthorizer" : [ ]
}, {
"api_key" : [ ]
} ]
我在每个方法上都使用它,因此,我遇到了很多错误。
奇怪的是我可以很好地克隆这个 API,因此,我假设我可以采用导出的定义并重新导入而不会出现问题。
关于如何纠正这些错误的任何想法(最好在我的 API 网关内,以便我可以毫无问题地导出/导入)。
我使用此授权方的 GET 方法之一的示例是:
"/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" : [ ]
} ]
}
提前致谢
更新
我在导入刚刚导出的定义时遇到的错误是:
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.
我在 API 中收到了每个方法的消息 - 所以有很多。
附加性,就在消息的末尾,我得到了这个:
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.
我试过忽略错误,结果相同。
确保您正在使用集成和授权扩展程序导出您的 swagger。
尝试使用 AWS CLI:
导出你的招摇
aws apigateway get-export \
--parameters '{"extensions":"integrations,authorizers"}' \
--rest-api-id {api_id} \
--stage-name {stage_name} \
--export-type swagger swagger.json
输出将发送到 swagger.json 文件。
有关 swagger 自定义扩展的更多详细信息,请参阅 this。
对于可能遇到此问题的任何人。
经过大量故障排除并最终涉及 AWS Support Team
,这已得到解决并确定为 AWS CLI
客户端错误(由 AWS Support Team
确认);
最终回复。
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
Create a file named data.json in the current directory where the powershell command is to be executed
Save the following contents to file {"extensions":"authorizers,integrations"}
In Powershell console, ensure the current working directory is the same as the location where data.json is present
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
使用它,终于解决了我的问题 - 我期待在即将发布的版本之一中进行修复。
PS - 目前最新版本:
aws --version
aws-cli/1.11.44 Python/2.7.9 Windows/8 botocore/1.5.7
我正在 API Gateway
.
所以,我从我的 AWS 账户中的 API Console
导出我的 API,然后我进入 API Gateway
并创建一个新的 API - "import from swagger".
我粘贴导出的定义并创建,这会引发大量错误。
根据我的阅读 - 这似乎是一个已知问题/痛苦。
我怀疑错误的原因是因为我使用了自定义授权方;
"security" : [ {
"TestAuthorizer" : [ ]
}, {
"api_key" : [ ]
} ]
我在每个方法上都使用它,因此,我遇到了很多错误。
奇怪的是我可以很好地克隆这个 API,因此,我假设我可以采用导出的定义并重新导入而不会出现问题。
关于如何纠正这些错误的任何想法(最好在我的 API 网关内,以便我可以毫无问题地导出/导入)。
我使用此授权方的 GET 方法之一的示例是:
"/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" : [ ]
} ]
}
提前致谢
更新
我在导入刚刚导出的定义时遇到的错误是:
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.
我在 API 中收到了每个方法的消息 - 所以有很多。
附加性,就在消息的末尾,我得到了这个:
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.
我试过忽略错误,结果相同。
确保您正在使用集成和授权扩展程序导出您的 swagger。
尝试使用 AWS CLI:
导出你的招摇aws apigateway get-export \
--parameters '{"extensions":"integrations,authorizers"}' \
--rest-api-id {api_id} \
--stage-name {stage_name} \
--export-type swagger swagger.json
输出将发送到 swagger.json 文件。
有关 swagger 自定义扩展的更多详细信息,请参阅 this。
对于可能遇到此问题的任何人。
经过大量故障排除并最终涉及 AWS Support Team
,这已得到解决并确定为 AWS CLI
客户端错误(由 AWS Support Team
确认);
最终回复。
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
Create a file named data.json in the current directory where the powershell command is to be executed
Save the following contents to file {"extensions":"authorizers,integrations"}
In Powershell console, ensure the current working directory is the same as the location where data.json is present
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
使用它,终于解决了我的问题 - 我期待在即将发布的版本之一中进行修复。
PS - 目前最新版本:
aws --version
aws-cli/1.11.44 Python/2.7.9 Windows/8 botocore/1.5.7