Error creating AWS API Gateway


#1

I am trying to run
webiny deploy-api and get the following error
Error: the specified api id "****" does not exist
at AwsApiGateway.default (/home/
/Code/wolffsen-cms/node_modules/@webiny/serverless-aws-api-gateway/serverless.js:84:23)
at processTicksAndRejections (internal/process/task_queues.js:86:5)


#2

Hi @Jonas,

I had the same issue and I made a successful deployment just 5 minutes ago.

Long story short

There’s a problem with emptying some local AWS cloudformation config files during api removal so the next deployment goes “dirty”.

You have to:

  • Remove deployment (you should get logs that tells you that some gateways with particular ids were not found. Example:
    An error occurred while removing i18n: NotFoundException: Invalid API identifier specified <AWS account id>:uipb10t47b).
  • Find text files in your webiny project that contains these ids. Probably JSONs.
  • Remove content of the file leaving only one pair of empty curly brackets {} inside.

Now it should be fine.

Also, run webiny deployment with --debug option to see if everything went fine. For example I had a problem with i18n gateway deployment. The gateway address was undefined:

webiny:i18n Finished API Gateway deployment: undefined +1ms

Explanation

After doing heavy api deployments and removals of the same environment (one by one) I got stuck with the same error as you had. I observed in AWS Api Gateway console that api gateway for i18n and Main Api Gateway are not being deployed. Every time I was redeploying my environment I found the i18n api id stays the same (Main Api Gateway api id was repetitive as well). To my understanding api id is generated by AWS every time new gateway is being deployed so I was sure there must be a record of this id in my local files.

First, I removed the deployment via webiny remove-api command. Then, I’ve done text search on my entire webiny project and I found that some files contain these ids. In api/.serverless files below were holding these values:

  • Webiny.local.api.AwsApiGateway.json
  • Webiny.local.i18n.json
  • Webiny.local.i18n.ServerlessApiGateway.AwsApiGateway.json
  • Webiny.local.i18n.ServerlessApiGateway.json

Also, I compared dev environment counterparts and the files were completely empty containing only one pair of curly brackets {}.

I removed the content of the local files and the deployment went smooth.

Possible reason

I was executing webiny remove-api && webiny deploy-api. The no time gap between these two commands could result that some AWS resources still exist (but pending to remove) even if the remove-api process was finished and deploy-api process has started. That could cause the local webiny deployment process interpreted the status of resources incorrectly and try to reuse old resources. The project has been deployed (or: was trying to be deployed) with incorrect configuration pointing to inexisting resources.

After that when I was executing webiny remove-api I was getting An error occurred while removing i18n: NotFoundException and the webiny process didn’t remove the old configuration from the JSON files. This configuration was reused causing Error: the specified api id "unbuatyxm7" does not exist error on the end of the deployment process.

I will try to reproduce the issue and if I will successfully do it I will report it as a bug.


#3

Hey @Peter_Palka, great answer. Just wanted to clarify that we don’t use CloudFormation at all; we use components and they work directly with the AWS SDK. But the rest of your answer is spot on. Sometimes the removal of resources gets messed up, and we still haven’t managed to find the exact reason nor reliably reproduce the error.

In any case, when this happens, the best thing to do is go to api/.serverless folder, and delete all .json files starting with Webiny. The only file that should be left in the folder is the _.json.

The resources created from the previous deployment would have to be cleaned up manually if you want to get rid of them in your AWS account. I know it’s annoying, but that’s how it is at this point.

Cheers!


#4

Hi @pavel,

Thanks for clarification. That will help to fix things if they will get broken. So far I could 't reproduce my issue but I got another one - webiny deploy-api creates a role and then shouts “the role already exist”. I’m investigating it and I will be more specific when I’ll understand what’s going on.

Thanks!