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):
- Create an API, add a (POST) method, of integration type "Mock"
- export via AWS CLI:
aws apigateway --profile "<MyAWSProfile>" get-export --rest-api-id <MyAPIid> --parameters extensions='apigateway' --stage-name <MyStageName> --export-type oas30 "api_definition.json"
- 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 :-))