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:
None of the links say that body response should be Base64
body
is clearly documented as // raw byte array representing the api definition
When importing rest-api into AWS API Gateway using the AWS CLI its not mandatory to encode the json as base64.
I suspect you are using AWS CLI v2 and this issue you are facing, I believe it's as a result of changes introduced in AWS CLI version 2. i.e
AWS CLI version 2 now passes all binary input and binary output parameters as base64-encoded strings by default
Resolution:
You will need add --cli-binary-format raw-in-base64-out so that it tells AWS CLI v2 to revert to the AWS CLI v1 behavior:
aws apigateway import-rest-api --cli-binary-format raw-in-base64-out --body file://my-api-apigateway.json
Using fileb://
instead of file://
worked for me. For example,
aws apigateway import-rest-api --body fileb://my-api.json
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With