

# Deleting products


When you delete a product, AWS Service Catalog removes all product versions from every portfolio containing the product. 

AWS Service Catalog allows you to delete a product using the AWS Service Catalog console or AWS CLI. To successfully delete a product, you must disassociate all resources associated with the product first. Examples of product resource associations include portfolio associations, budgets, TagOptions, and Service Actions. 

**Important**  
 You cannot recover a product after it is deleted. 

**To delete a product using the AWS Service Catalog console**

1.  Navigate to the **Portfolios** page and select the portfolio containing the product you want to delete. 

1.  Select the product that you want to delete, and then choose **Delete** on the upper right of the product pane. 

1. For products *without associated resources*, confirm the product you want to delete by entering **delete** in the text box, and then choose **Delete**. 

   For products *with associated resources*, continue to step 4. 

1. In the **Delete product** window, review the **Associations** table, which displays all of the product's associated resources. AWS Service Catalog attempts to disassociate these resources when you delete the product. 

1. Confirm you want to delete the product and remove all of its associated resources by entering **delete** in the text box. 

1. Choose **Disassociate and delete**. 

If AWS Service Catalog is unable to disassociate all of the product's resources, the product is not deleted. The **Delete product** window displays the number of failed disassociations and a description for each failure. For more information about resolving failed resource disassociations when deleting a product, see * Resolving failed resource disassociations when deleting a product* below. 

**Topics**
+ [

# Deleting products using the AWS CLI
](product-delete-cli.md)
+ [

# Resolving failed resource disassociations when deleting a product
](product-delete-exception.md)

# Deleting products using the AWS CLI


AWS Service Catalog allows you to use the [AWS Command Line Interface](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) (AWS CLI) to delete products from your portfolio. The AWS CLI is an open source tool that enables you to interact with AWS services using commands in your command-line shell. The AWS Service Catalog force-delete function requires an [AWS CLI alias](https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-alias.html), which is a shortcut you can create in the AWS CLI to shorten commands or scripts that you frequently use. 

## Prerequisites

+ Install and configure the AWS CLI. For more information, see [ Installing or updating the latest version of the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) and [ Configuration basics](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html). Use a minimum AWS CLI version of 1.11.24 or 2.0.0. 
+ The delete product CLI alias requires a bash-compatible terminal and the JQ command-line JSON processor. For more information about installing the Command-line JSON processor, see [Download jq](https://stedolan.github.io/jq/download/). 
+ Create a AWS CLI Alias to batch `Disassociation` API calls, enabling you to delete a product in a single command. 

To successfully delete a product, you must disassociate all resources associated with the product first. Examples of product resource associations include portfolio associations, budgets, Tag Options, and Service Actions. When using the CLI to delete a product, the CLI `force-delete-product` alias enables you to call the `Disassociate` API to disassociate any resources that would prevent the `DeleteProduct` API. This avoids a seperate call for individual disassociations. 

**Note**  
The file paths shown in the procedures below may vary depending on which operating system you use to perform these actions. 

## Creating an AWS CLI alias to delete AWS Service Catalog products


When using the AWS CLI to delete a AWS Service Catalog product, the CLI `force-delete-product` alias enables you to call the `Disassociate` API to disassociate any resources that would prevent the `DeleteProduct` call. 

**Create an `alias` file in your AWS CLI configuration folder**

1. In the AWS CLI console, navigate to the configuraiton folder. By default, the configuration folder path is `~/.aws/` on Linux and macOS, or `%USERPROFILE%\.aws\` on Windows. 

1. Create a sub-folder named `cli` using file navigation or by entering the following command in your preferred terminal: 

   ```
                $ mkdir -p ~/.aws/cli
   ```

   The resulting `cli` folder default path is `~/.aws/cli/` on Linux and MacOS, or `%USERPROFILE%\.aws\cli` on Windows. 

1. In the new `cli` folder, create a text file named `alias` with no file extension. You can create the `alias` file using file navigation or by entering the following command in your preferred terminal: 

   ```
                 $ touch ~/.aws/cli/alias
   ```

1. Enter `[toplevel]` on the first line.

1. Save the file. 

Next, you can add the force-delete-product alias to your `alias` file by manually pasting the alias script into the file, or by using a command in the terminal window. 

**Manually add the force-delete-product alias to your `alias` file**

1. In the AWS CLI console, navigate to your AWS CLI configuration folder and open the `alias` file. 

1. Enter the following code alias into the file, below the `[toplevel]` line: 

   ```
                [command servicecatalog]
             	 force-delete-product =
             	   !f() {
             	     if [ "$#" -ne 1 ]; then
             	         echo "Illegal number of parameters"
             	         exit 1
             	     fi
             	 
             	     if [[ "$1" != prod-* ]]; then
             	        echo "Please provide a valid product id."
             	        exit 1
             	     fi
             	 
             	     productId=$1
             	     describeProductAsAdminResponse=$(aws servicecatalog describe-product-as-admin --id $productId)
             	     listPortfoliosForProductResponse=$(aws servicecatalog list-portfolios-for-product --product-id $productId)
             	 
             	     tagOptions=$(echo "$describeProductAsAdminResponse" | jq -r '.TagOptions[].Id')
             	     budgetName=$(echo "$describeProductAsAdminResponse" | jq -r '.Budgets[].BudgetName')
             	     portfolios=$(echo "$listPortfoliosForProductResponse" | jq -r '.PortfolioDetails[].Id')
             	     provisioningArtifacts=$(echo "$describeProductAsAdminResponse" | jq -r '.ProvisioningArtifactSummaries[].Id')
             	     provisioningArtifactServiceActionAssociations=()
             	 
             	     for provisioningArtifactId in $provisioningArtifacts; do
             	       listServiceActionsForProvisioningArtifactResponse=$(aws servicecatalog list-service-actions-for-provisioning-artifact --product-id $productId --provisioning-artifact-id $provisioningArtifactId)
             	       serviceActions=$(echo "$listServiceActionsForProvisioningArtifactResponse" | jq -r '[.ServiceActionSummaries[].Id] | join(",")')
             	       if [[ -n "$serviceActions" ]]; then
             	         provisioningArtifactServiceActionAssociations+=("${provisioningArtifactId}:${serviceActions}")
             	       fi
             	     done
             	 
             	     echo "Before deleting a product, the following associated resources must be disassociated. These resources will not be deleted. This action may take some time, depending on the number of resources being disassociated."
             	 
             	     echo "Portfolios:"
             	     for portfolioId in $portfolios; do
             	       echo "\t${portfolioId}"
             	     done
             	 
             	     echo "Budgets:"
             	     if [[ -n "$budgetName" ]]; then
             	       echo "\t${budgetName}"
             	     fi
             	 
             	     echo "Tag Options:"
             	     for tagOptionId in $tagOptions; do
             	       echo "\t${tagOptionId}"
             	     done
             	 
             	     echo "Service Actions on Provisioning Artifact:"
             	     for association in "${provisioningArtifactServiceActionAssociations[@]}"; do
             	       echo "\t${association}"
             	     done
             	 
             	     read -p "Are you sure you want to delete ${productId}? y,n "
             	     if [[ ! $REPLY =~ ^[Yy]$ ]]; then
             	        exit
             	     fi
             	 
             	     for portfolioId in $portfolios; do
             	       echo "Disassociating ${portfolioId}"
             	       aws servicecatalog disassociate-product-from-portfolio --product-id $productId --portfolio-id $portfolioId
             	     done
             	 
             	     if [[ -n "$budgetName" ]]; then
             	       echo "Disassociating ${budgetName}"
             	       aws servicecatalog disassociate-budget-from-resource --budget-name "$budgetName" --resource-id $productId
             	     fi
             	 
             	     for tagOptionId in $tagOptions; do
             	       echo "Disassociating ${tagOptionId}"
             	       aws servicecatalog disassociate-tag-option-from-resource --tag-option-id $tagOptionId --resource-id $productId
             	     done
             	 
             	     for association in "${provisioningArtifactServiceActionAssociations[@]}"; do
             	       associationPair=(${association//:/ })
             	       provisioningArtifactId=${associationPair[0]}
             	       serviceActionsList=${associationPair[1]}
             	       serviceActionIds=${serviceActionsList//,/ }
             	       for serviceActionId in $serviceActionIds; do
             	         echo "Disassociating ${serviceActionId} from ${provisioningArtifactId}"
             	         aws servicecatalog disassociate-service-action-from-provisioning-artifact --product-id $productId --provisioning-artifact-id $provisioningArtifactId --service-action-id $serviceActionId
             	       done
             	     done
             	 
             	     echo "Deleting product ${productId}"
             	     aws servicecatalog delete-product --id $productId
             	 
             	   }; f
   ```

1. Save the file. 

**Use the terminal window to add the force-delete-product alias to your `alias` file**

1. Open your terminal window and run the following command

   `$ cat >> ~/.aws/cli/alias`

1. Paste the alias script to the terminal window, and then press *CTRL\$1D* to exit the `cat` command. 

**Call the force-delete-product alias**

1. In your terminal window, run the following command to call the delete product alias

   `$ aws servicecatalog force-delete-product {product-id} `

   The example below shows the `force-delete-product` alias command and its resulting response 

   ```
                 $ aws servicecatalog force-delete-product prod-123
   ```

   ```
                 Before deleting a product, the following associated resources must be disassociated. These resources will not be deleted. This action may take some time, depending on the number of resources being disassociated.
                 Portfolios:
                   port-123
                 Budgets:
                     budgetName
                 Tag Options:
                     tag-123
                 Service Actions on Provisioning Artifact:
                     pa-123:act-123
                 Are you sure you want to delete prod-123? y,n
   ```

1. Enter `y` to confirm you want to delete the product. 

After successfully deleting the product, the terminal window displays the following results

```
          Disassociating port-123
          Disassociating budgetName
          Disassociating tag-123
          Disassociating act-123 from pa-123
          Deleting product prod-123
```

## Additional resources


For more information about AWS CLI, using aliases, and deleting AWS Service Catalog products, review the following resources:
+ [ Creating and using AWS CLI aliases](https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-alias.html) in the *AWS Command Line Interface (CLI)* user guide. 
+ [AWS CLI alias repository](https://github.com/awslabs/awscli-aliases) git repository. 
+ [Deleting AWS Service Catalog products](https://docs.aws.amazon.com/servicecatalog/latest/adminguide/productmgmt-delete.html). 
+ [AWS re:Invent 2016: The Effective AWS CLI User](https://youtu.be/Xc1dHtWa9-Q?t=1593) on *YouTube*. 

# Resolving failed resource disassociations when deleting a product


If your prior attempt to [delete a product](https://docs.aws.amazon.com/servicecatalog/latest/adminguide/productmgmt-delete.html) failed due to resource disassociation exceptions, review the list of exceptions and their resolutions below. 

**Note**  
If you closed the **Deleting products** window prior to receiving the failed resource disassociation message, you can follow steps one through three in the proceeding *Delete a product* section to open the window again.

**To resolve a failed resource disassociation**

In the **Delete product** window, review the Associations table **Status** column. Identify the failed resource disassociation exception and the suggested resolutions:


****  

| Status exception type | Cause | Resolution | 
| --- | --- | --- | 
| Product prod-\$1\$1\$1\$1 | AWS Service Catalog could not delete the product because the product still has associated TagOptions, budgets, at least one ProvisioningArtifact with associated actions, the product is still assigned to a Portfolio, the product has users, or the product has constraints.  | Attempt to delete the product again. | 
| User: username is not authorized to perform: | The user attempting to delete the product does not have the necessary permissions to disassociate the product's resources.  | AWS Service Catalog recommends contacting your account administrator for more information about disassociating product resources you do not currently have permissions to disassociate.  | 