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
asked 4 years ago4865 views
2 Answers
0
Accepted Answer

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
answered 4 years ago
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
answered 4 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions