Use DeleteRestApi with an AWS SDK or CLI - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Use DeleteRestApi with an AWS SDK or CLI

The following code examples show how to use DeleteRestApi.

Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:

CLI
AWS CLI

To delete an API

Command:

aws apigateway delete-rest-api --rest-api-id 1234123412
  • For API details, see DeleteRestApi in AWS CLI Command Reference.

Java
SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

public static void deleteAPI(ApiGatewayClient apiGateway, String restApiId) { try { DeleteRestApiRequest request = DeleteRestApiRequest.builder() .restApiId(restApiId) .build(); apiGateway.deleteRestApi(request); System.out.println("The API was successfully deleted"); } catch (ApiGatewayException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • For API details, see DeleteRestApi in AWS SDK for Java 2.x API Reference.

Python
SDK for Python (Boto3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

class ApiGatewayToService: """ Encapsulates Amazon API Gateway functions that are used to create a REST API that integrates with another AWS service. """ def __init__(self, apig_client): """ :param apig_client: A Boto3 API Gateway client. """ self.apig_client = apig_client self.api_id = None self.root_id = None self.stage = None def delete_rest_api(self): """ Deletes a REST API, including all of its resources and configuration. """ try: self.apig_client.delete_rest_api(restApiId=self.api_id) logger.info("Deleted REST API %s.", self.api_id) self.api_id = None except ClientError: logger.exception("Couldn't delete REST API %s.", self.api_id) raise
  • For API details, see DeleteRestApi in AWS SDK for Python (Boto3) API Reference.