API export and import - Invalid OpenAPI input.

0

I run into an error when trying to import a API definition in JSON format via the AWS CLI.

The file I try to import, is an export of that same API, which I exported also via the AWS CLI. Moreover, if I import that JSON via the AWS web console (via Gateway > API > Resources > Actions > import..) it works just fine.

I have this with my project API, but I could also reproduce it with a simple API definition;

Reproduction steps (be sure to replace the <variable> parts):

  1. Create an API, add a (POST) method, of integration type "Mock"
  2. export via AWS CLI:
aws apigateway --profile "<MyAWSProfile>" get-export --rest-api-id <MyAPIid> --parameters extensions=&#39;apigateway&#39; --stage-name <MyStageName> --export-type oas30  "api_definition.json"
  1. import via AWS CLI:
aws apigateway --profile "<MyAWSProfile>" put-rest-api --rest-api-id <MyAPIid> --mode overwrite --body "api_definition.json"

The above gives this trace + error:

2020-04-28 15:21:59,700 - MainThread - awscli.clidriver - DEBUG - Exception caught in main()
Traceback (most recent call last):
  File ".\lib\site-packages\awscli\clidriver.py", line 217, in main
    return command_table[parsed_args.command](remaining, parsed_args)
  File ".\lib\site-packages\awscli\clidriver.py", line 358, in __call__
    return command_table[parsed_args.operation](remaining, parsed_globals)
  File ".\lib\site-packages\awscli\clidriver.py", line 530, in __call__
    call_parameters, parsed_globals)
  File ".\lib\site-packages\awscli\clidriver.py", line 650, in invoke
    client, operation_name, parameters, parsed_globals)
  File ".\lib\site-packages\awscli\clidriver.py", line 662, in _make_client_call
    **parameters)
  File ".\lib\site-packages\botocore\client.py", line 316, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File ".\lib\site-packages\botocore\client.py", line 626, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.errorfactory.BadRequestException: An error occurred (BadRequestException) when calling the PutRestApi operation: Invalid OpenAPI input.
2020-04-28 15:21:59,702 - MainThread - awscli.clidriver - DEBUG - Exiting with rc 255

An error occurred (BadRequestException) when calling the PutRestApi operation: Invalid OpenAPI input.

I would expect that an import via the AWS CLI of the exported definition (exported via the same tool) would just work. Am I overlooking something? Beginners mistake? (I am fairly new to AWS :-))

DTR
질문됨 4년 전4490회 조회
2개 답변
0
수락된 답변

Hello, it should work if you use file://api_definition.json for the "put-rest-api --body" parameter. Can you give that a try?

AWS
답변함 4년 전
0

Thanks Alan, that solves it! Great!

I had tried this file:// prepend before to no avail, but must have made a mistake with the slashes or so.

Luckily (for anyone reading this) it also works with relative paths "file://.\api\definition.json" on windows.

DTR
답변함 4년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠