I am trying to export and than import AWS Gateway API, following the instructions in https://aws.amazon.com/premiumsupport/knowledge-center/api-gateway-migrate-accounts-regions/.
Export is working:
aws apigateway get-export --parameters extensions='apigateway' --rest-api-id MY_REST_API_ID --stage-name Prod --export-type swagger my-api-apigateway.json
Identical files for my API are generated with --parameters extensions='apigateway'
and --parameters extensions='integrations'
.
But when I try to do the import from the exported file:
aws apigateway import-rest-api --fail-on-warnings --body file://%cd%/my-api-gateway.json
, I am always getting "Invalid base64: " error. Like this:
Invalid base64: "{
"swagger" : "2.0",
"info" : {
"version" : "1.0",
"title" : "my-stack-name"
},
"host" : "MY_REST_API_ID.execute-api.eu-central-1.amazonaws.com",
"basePath" : "/Prod",
...
No documentation and no examples on google say that body should be Base64.
The same JSON seems to work when I import it via UI (Actions -> Import API).
I've also tried to use --cli-input-json
:
my-api-apigateway-cli-json.json
file (according to aws apigateway import-rest-api --generate-cli-skeleton
):
{
"failOnWarnings": true,
"parameters": {
"endpointConfigurationTypes": "REGIONAL"
},
"body": {... JSON FROM EXPORT ...}
}
Import command:
aws apigateway import-rest-api --cli-input-json file://./my-api-apigateway-cli-json.json
, but it says
Parameter validation failed:
Invalid type for parameter body, value: {'swagger': '2.0', ...
So, the questions are:
- Should we encode the json as base64?
- Why is this error and behaviour not documented (or if yes, then where?)?
- How to successfully execute import from cli?
Useful links
None of the links say that body response should be Base64
- https://docs.aws.amazon.com/apigateway/api-reference/link-relation/restapi-import/ -- here
body
is clearly documented as// raw byte array representing the api definition