By using AWS re:Post, you agree to the AWS re:Post Terms of Use

Cannot Remove APIs - Please remove all base path mappings related to the RestApi in your domains

0

I am trying to delete some old APIGateway apis to lower my bills for unused resources. I am getting this error for several old APIs:

Deleting RestApi zd4yc2jmq8 failed. Please remove all base path mappings related to the RestApi in your domains: api.stakepica.com

There is no entry in custom domain names, not even an entry in route 53. I also tried deleting these APIs through the cli but I got the same error. I also searched for "hidden" entries using the cli:

aws apigateway get-domain-names --query "items[?domainName=='api.stakepara.com']"

but it returns [ ], in line with the dashboard data. Note that the APIs are not part of a cloudformation stack. Here is the ARN for api.stakepara.com api: arn:aws:apigateway:us-east-1::/restapis/zg8azx8n80

Also, note that this is not happening for all APIs. I was able to delete some of them.

3 Answers
1

The issue you're experiencing is related to base path mappings that are still associated with your API, even though they may not be visible in the console or through standard CLI commands. This can happen when there are lingering associations between your API and custom domain names.

To resolve this issue, you'll need to remove the base path mappings before you can delete the API. Here's a step-by-step approach to tackle this problem:

  1. First, try to delete the base path mapping using the AWS CLI. Use the following command:

    aws apigateway delete-base-path-mapping --domain-name api.stakepara.com --base-path 'dev'

    Replace 'dev' with the appropriate base path if it's different. If you're unsure of the base path, you might need to try variations like '' (empty string) for the root path.

  2. If the above command doesn't work or you're unsure of the exact base path, you can try to delete the API mapping instead:

    aws apigatewayv2 delete-api-mapping --api-mapping-id [API_MAPPING_ID] --domain-name api.stakepara.com

    You'll need to replace [API_MAPPING_ID] with the actual ID of the API mapping. If you don't know this ID, you may need to list all API mappings for the domain and identify the correct one.

  3. If these steps don't resolve the issue, you might need to delete the custom domain name entirely:

    aws apigateway delete-domain-name --domain-name api.stakepara.com

  4. After successfully removing the base path mappings or the custom domain, try deleting the API again using:

    aws apigateway delete-rest-api --rest-api-id zg8azx8n80

If you're still encountering issues after trying these steps, it's possible that there might be some inconsistency in the API Gateway backend. In such cases, it's best to contact AWS Support for further assistance. They can help investigate any hidden associations or backend issues that might be preventing the API deletion.

Remember to be cautious when deleting resources, especially in production environments, as these actions are irreversible and could impact your applications if not done carefully.
Sources
delete-base-path-mapping — AWS CLI 2.19.0 Command Reference
Cannot delete API | AWS re:Post
delete-api-mapping — AWS CLI 2.19.1 Command Reference
delete-rest-api — AWS CLI 2.19.0 Command Reference

profile picture
answered a month ago
profile picture
EXPERT
reviewed a month ago
  • On 1, there is no such base path, On 2, there is no mapping. On 3, there is no domain entry in route 53 for this (for the entire domain) On 4, we have tried both the cli and the dashbaord, same error.

0

Hi,

Try from the CLI:

aws apigateway delete-base-path-mapping --domain-name stakepara.com --base-path "(none)"

Then the deletion of the GTW APIs should work

Best,

Didier

profile pictureAWS
EXPERT
answered a month ago
profile picture
EXPERT
reviewed a month ago
0

Hi, thanks. there is no such mapping. It's there there when i check the dashboard or when i list through the cli. Also, trying to delete it results to this:

An error occurred (NotFoundException) when calling the DeleteBasePathMapping operation: Invalid domain name identifier specified

Also

C:\Users\itsio>aws apigateway get-base-path-mappings --domain-name stakepara.com
An error occurred (NotFoundException) when calling the GetBasePathMappings operation: Invalid domain name identifier specified

That's why this is so weird. AWS will not let me delete the api gateway for api.satkepara.com (and other apis) because of a custom mapping that does not exist.

This probably happened cause i moved some domains from AWS to another registrar, and also deleted the records in Route 53. My guess is that this resulted to automatic removal of the customd omain records in api gateway, but some flags were not updated on the apis themselves.

answered a month 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