

# Managing an Amazon Rekognition Custom Labels project
<a name="managing-project"></a>

Within Amazon Rekognition Custom Labels, you use a project to manage the models that you create for a specific use case. A project manages datasets, model training, model versions, model evaluation, and the running of your project's models. 

**Topics**
+ [

# Deleting an Amazon Rekognition Custom Labels project
](mp-delete-project.md)
+ [

# Describing a project (SDK)
](md-describing-project-sdk.md)
+ [

# Creating a project with AWS CloudFormation
](cloudformation.md)

# Deleting an Amazon Rekognition Custom Labels project
<a name="mp-delete-project"></a>

You can delete a project by using the Amazon Rekognition console or by calling the [DeleteProject](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DeleteProject) API. To delete a project, you must first delete each associated model. A deleted project or model can't be undeleted. 

**Topics**
+ [

## Deleting an Amazon Rekognition Custom Labels project (Console)
](#mp-delete-project-console)
+ [

## Deleting an Amazon Rekognition Custom Labels project (SDK)
](#mp-delete-project-sdk)

## Deleting an Amazon Rekognition Custom Labels project (Console)
<a name="mp-delete-project-console"></a>

You can delete a project from the projects page, or you can delete a project from a project's detail page. The following procedure shows you how to delete a project using the projects page.

The Amazon Rekognition Custom Labels console deletes associated models and datasets for you during project deletion. You can't delete a project if any of its models are running or training. To stop a running model, see [Stopping an Amazon Rekognition Custom Labels model (SDK)](rm-stop.md#rm-stop-sdk). If a model is training, wait until it finishes before you delete the project.

**To delete a project (console)**

1. Open the Amazon Rekognition console at [https://console.aws.amazon.com/rekognition/](https://console.aws.amazon.com/rekognition/).

1. Choose **Use Custom Labels**.

1. Choose **Get started**. 

1. In the left navigation pane, choose **Projects**.

1. On the **Projects** page, select the radio button for the project that you want to delete. The project list showing echo-devices-project, with 1 version created on 2020-03-25, and options to Delete, Train new model, or Create project.  
![\[Project list showing the echo-devices-project project and project details.\]](http://docs.aws.amazon.com/rekognition/latest/customlabels-dg/images/delete-projects-page.png)

1. Choose **Delete** at the top of the page. The **Delete project** dialog box is shown.

1. If the project has no associated models:

   1. Enter **delete** to delete the project.

   1. Choose **Delete** to delete the project.

1. If the project has associated models or datasets:

   1. Enter **delete** to confirm that you want to delete the model(s) and datasets.

   1. Choose either **Delete associated models** or **Delete associated datasets** or **Delete associated datasets and models**, depending on whether the model has datasets, models, or both. Model deletion might take a while to complete.
**Note**  
The console can't delete models that are in-training or running. Try again after stopping any running models that are listed, and wait until models listed as training finish.  
If you **Close** the dialog box during model deletion, the models are still deleted. Later, you can delete the project by repeating this procedure. 

       The panel for deleting a model gives you explicit instructions to delete associated models.   
![\[Interface for deleting a project.\]](http://docs.aws.amazon.com/rekognition/latest/customlabels-dg/images/delete-project-with-models.png)

   1. Enter **delete** to confirm that you want to delete the project.

   1. Choose **Delete** to delete the project.  
![\[Dialog box confirming deletion of "echo-devices-project" project with no models.\]](http://docs.aws.amazon.com/rekognition/latest/customlabels-dg/images/delete-project.png)

## Deleting an Amazon Rekognition Custom Labels project (SDK)
<a name="mp-delete-project-sdk"></a>

You delete an Amazon Rekognition Custom Labels project by calling [DeleteProject](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DeleteProject) and supplying the Amazon Resource Name (ARN) of the project that you want to delete. To get the ARNs of the projects in your AWS account, call [DescribeProjects](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DescribeProjects). The response includes an array of [ProjectDescription](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_ProjectDescription) objects. The project ARN is the `ProjectArn` field. You can use the project name to identify the ARN of the project. For example, `arn:aws:rekognition:us-east-1:123456789010:project/project name/1234567890123`. 

Before you can delete a project, you must first delete all models and datasets in the project. For more information, see [Deleting an Amazon Rekognition Custom Labels model (SDK)](tm-delete-model.md#tm-delete-model-sdk) and [Deleting a dataset](md-delete-dataset.md).

The project might take a few moments to delete. During that time, the status of the project is `DELETING`. The project is deleted if a subsequent call to [DescribeProjects](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DescribeProjects) doesn't include the project that you deleted.

**To delete a project (SDK)**

1. If you haven't already done so, install and configure the AWS CLI and the AWS SDKs. For more information, see [Step 4: Set up the AWS CLI and AWS SDKs](su-awscli-sdk.md).

1. Use the following code to delete a project. 

------
#### [ AWS CLI ]

   Change the value of `project-arn` to the name of the project that you want to delete.

   ```
   aws rekognition delete-project --project-arn project_arn \
     --profile custom-labels-access
   ```

------
#### [ Python ]

   Use the following code. Supply the following command line parameters:
   + `project_arn`— the ARN of the project that you want to delete.

   ```
   # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
   # SPDX-License-Identifier: Apache-2.0
   
   """
   Purpose
   Amazon Rekognition Custom Labels project example used in the service documentation:
   https://docs.aws.amazon.com/rekognition/latest/customlabels-dg/mp-delete-project.html
   Shows how to delete an existing Amazon Rekognition Custom Labels project. 
   You must first delete any models and datasets that belong to the project.
   """
   
   import argparse
   import logging
   import time
   import boto3
   
   
   from botocore.exceptions import ClientError
   
   logger = logging.getLogger(__name__)
   
   
   def find_forward_slash(input_string, n):
       """
       Returns the location of '/' after n number of occurences. 
       :param input_string: The string you want to search
       : n: the occurence that you want to find.
       """
       position = input_string.find('/')
       while position >= 0 and n > 1:
           position = input_string.find('/', position + 1)
           n -= 1
       return position
   
   
   def delete_project(rek_client, project_arn):
       """
       Deletes an Amazon Rekognition Custom Labels project.
       :param rek_client: The Amazon Rekognition Custom Labels Boto3 client.
       :param project_arn: The ARN of the project that you want to delete.
       """
   
       try:
           # Delete the project
           logger.info("Deleting project: %s", project_arn)
   
           response = rek_client.delete_project(ProjectArn=project_arn)
   
           logger.info("project status: %s",response['Status'])
   
           deleted = False
   
           logger.info("waiting for project deletion: %s", project_arn)
   
           # Get the project name
           start = find_forward_slash(project_arn, 1) + 1
           end = find_forward_slash(project_arn, 2)
           project_name = project_arn[start:end]
   
           project_names = [project_name]
   
           while deleted is False:
   
               project_descriptions = rek_client.describe_projects(
                   ProjectNames=project_names)['ProjectDescriptions']
   
               if len(project_descriptions) == 0:
                   deleted = True
   
               else:
                   time.sleep(5)
   
           logger.info("project deleted: %s",project_arn)
   
           return True
   
       except ClientError as err:
           logger.exception(
               "Couldn't delete project - %s: %s",
               project_arn, err.response['Error']['Message'])
           raise
   
   
   def add_arguments(parser):
       """
       Adds command line arguments to the parser.
       :param parser: The command line parser.
       """
   
       parser.add_argument(
           "project_arn", help="The ARN of the project that you want to delete."
       )
   
   
   def main():
   
       logging.basicConfig(level=logging.INFO,
                           format="%(levelname)s: %(message)s")
   
       try:
   
           # get command line arguments
           parser = argparse.ArgumentParser(usage=argparse.SUPPRESS)
           add_arguments(parser)
           args = parser.parse_args()
   
           print(f"Deleting project: {args.project_arn}")
   
           # Delete the project.
           session = boto3.Session(profile_name='custom-labels-access')
           rekognition_client = session.client("rekognition")
   
           delete_project(rekognition_client,
                          args.project_arn)
   
           print(f"Finished deleting project: {args.project_arn}")
   
       except ClientError as err:
           error_message = f"Problem deleting project: {err}"
           logger.exception(error_message)
           print(error_message)
   
   
   if __name__ == "__main__":
       main()
   ```

------
#### [ Java V2 ]

   Use the following code. Supply the following command line parameters:
   + `project_arn`— the ARN of the project that you want to delete.

   ```
   /*
   Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
   SPDX-License-Identifier: Apache-2.0
   */
   
   package com.example.rekognition;
   
   import java.util.List;
   import java.util.Objects;
   import java.util.logging.Level;
   import java.util.logging.Logger;
   
   import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
   import software.amazon.awssdk.regions.Region;
   import software.amazon.awssdk.services.rekognition.RekognitionClient;
   import software.amazon.awssdk.services.rekognition.model.DeleteProjectRequest;
   import software.amazon.awssdk.services.rekognition.model.DeleteProjectResponse;
   import software.amazon.awssdk.services.rekognition.model.DescribeProjectsRequest;
   import software.amazon.awssdk.services.rekognition.model.DescribeProjectsResponse;
   import software.amazon.awssdk.services.rekognition.model.ProjectDescription;
   import software.amazon.awssdk.services.rekognition.model.RekognitionException;
   
   public class DeleteProject {
   
       public static final Logger logger = Logger.getLogger(DeleteProject.class.getName());
   
       public static void deleteMyProject(RekognitionClient rekClient, String projectArn) throws InterruptedException {
   
           try {
   
               logger.log(Level.INFO, "Deleting project: {0}", projectArn);
   
               // Delete the project
   
               DeleteProjectRequest deleteProjectRequest = DeleteProjectRequest.builder().projectArn(projectArn).build();
               DeleteProjectResponse response = rekClient.deleteProject(deleteProjectRequest);
   
               logger.log(Level.INFO, "Status: {0}", response.status());
   
               // Wait until deletion finishes
   
               Boolean deleted = false;
   
               do {
   
   				    DescribeProjectsRequest describeProjectsRequest = DescribeProjectsRequest.builder().build();
                       DescribeProjectsResponse describeResponse = rekClient.describeProjects(describeProjectsRequest);
                       List<ProjectDescription> projectDescriptions = describeResponse.projectDescriptions();
   
                       deleted = true;
   
                       for (ProjectDescription projectDescription : projectDescriptions) {
   
                           if (Objects.equals(projectDescription.projectArn(), projectArn)) {
                               deleted = false;
                               logger.log(Level.INFO, "Not deleted: {0}", projectDescription.projectArn());
                               Thread.sleep(5000);
                               break;
                           }
                       }
   
               } while (Boolean.FALSE.equals(deleted));
   
               logger.log(Level.INFO, "Project deleted: {0} ", projectArn);
   
           } catch (
   
           RekognitionException e) {
               logger.log(Level.SEVERE, "Client error occurred: {0}", e.getMessage());
               throw e;
           }
   
       }
   
       public static void main(String[] args) {
   
           final String USAGE = "\n" + "Usage: " + "<project_arn>\n\n" + "Where:\n"
                + "   project_arn - The ARN of the project that you want to delete.\n\n";
   
           if (args.length != 1) {
                System.out.println(USAGE);
   	         System.exit(1);
           }
   
           String projectArn = args[0];
   
           try {
   
               RekognitionClient rekClient = RekognitionClient.builder()
                   .region(Region.US_WEST_2)
                   .credentialsProvider(ProfileCredentialsProvider.create("custom-labels-access"))
                   .build();
   
               // Delete the project.
               deleteMyProject(rekClient, projectArn);
   
               System.out.println(String.format("Project deleted: %s", projectArn));
   
               rekClient.close();
   
           } catch (RekognitionException rekError) {
               logger.log(Level.SEVERE, "Rekognition client error: {0}", rekError.getMessage());
               System.exit(1);
           }
   
           catch (InterruptedException intError) {
               logger.log(Level.SEVERE, "Exception while sleeping: {0}", intError.getMessage());
               System.exit(1);
           }
       }
   
   }
   ```

------

# Describing a project (SDK)
<a name="md-describing-project-sdk"></a>

You can use the `DescribeProjects` API to get information about your projects.

**To describe a project (SDK)**

1. If you haven't already done so, install and configure the AWS CLI and the AWS SDKs. For more information, see [Step 4: Set up the AWS CLI and AWS SDKs](su-awscli-sdk.md).

1. Use the following example code to describe a project. Replace `project_name` with the name of the project that you want to describe. If you don't specify `--project-names`, desriptions for all projects are returned.

------
#### [ AWS CLI ]

   ```
   aws rekognition describe-projects --project-names project_name \
     --profile custom-labels-access
   ```

------
#### [ Python ]

   Use the following code. Supply the following command line parameters:
   + project\$1name``— the name of the project that you want to describe. If you don't specify a name, descriptions for all projects are returned.

   ```
   # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
   # SPDX-License-Identifier: Apache-2.0
   
   """
   Purpose
   Shows how to describe an Amazon Rekognition Custom Labels project.
   """
   import argparse
   import logging
   import json
   import boto3
   from botocore.exceptions import ClientError
   
   logger = logging.getLogger(__name__)
   
   
   def display_project_info(project):
       """
       Displays information about a Custom Labels project.
       :param project: The project that you want to display information about.
       """
       print(f"Arn: {project['ProjectArn']}")
       print(f"Status: {project['Status']}")
   
       if len(project['Datasets']) == 0:
           print("Datasets: None")
       else:
           print("Datasets:")
   
       for dataset in project['Datasets']:
           print(f"\tCreated: {str(dataset['CreationTimestamp'])}")
           print(f"\tType: {dataset['DatasetType']}")
           print(f"\tARN: {dataset['DatasetArn']}")
           print(f"\tStatus: {dataset['Status']}")
           print(f"\tStatus message: {dataset['StatusMessage']}")
           print(f"\tStatus code: {dataset['StatusMessageCode']}")
           print()
       print()
   
   
   def describe_projects(rek_client, project_name):
       """
       Describes an Amazon Rekognition Custom Labels project, or all projects.
       :param rek_client: The Amazon Rekognition Custom Labels Boto3 client.
       :param project_name: The project you want to describe. Pass None to describe all projects.
       """
   
       try:
           # Describe the project
           if project_name is None:
               logger.info("Describing all projects.")
           else:
               logger.info("Describing project: %s.",project_name)
   
           if project_name is None:
               response = rek_client.describe_projects()
           else:
               project_names = json.loads('["' + project_name + '"]')
               response = rek_client.describe_projects(ProjectNames=project_names)
   
           print('Projects\n--------')
           if len(response['ProjectDescriptions']) == 0:
               print("Project(s) not found.")
           else:
               for project in response['ProjectDescriptions']:
                   display_project_info(project)
   
           logger.info("Finished project description.")
   
       except ClientError as err:
           logger.exception(
               "Couldn't describe project - %s: %s",
               project_name,err.response['Error']['Message'] )
           raise
   
   
   def add_arguments(parser):
       """
       Adds command line arguments to the parser.
       :param parser: The command line parser.
       """
   
       parser.add_argument(
           "--project_name",  help="The name of the project that you want to describe.", required=False
       )
   
   
   def main():
   
       logging.basicConfig(level=logging.INFO,
                           format="%(levelname)s: %(message)s")
   
       try:
   
           # Get command line arguments.
           parser = argparse.ArgumentParser(usage=argparse.SUPPRESS)
           add_arguments(parser)
   
           args = parser.parse_args()
   
           print(f"Describing projects: {args.project_name}")
   
           # Describe the project.
           session = boto3.Session(profile_name='custom-labels-access')
           rekognition_client = session.client("rekognition")
   
           describe_projects(rekognition_client,
                             args.project_name)
   
           if args.project_name is None:
               print("Finished describing all projects.")
           else:
               print("Finished describing project %s.", args.project_name)
   
       except ClientError as err:
           error_message = f"Problem describing project: {err}"
           logger.exception(error_message)
           print(error_message)
   
   
   if __name__ == "__main__":
       main()
   ```

------
#### [ Java V2 ]

   Use the following code. Supply the following command line parameters:
   + `project_name` — the ARN of the project that you want to describe. If you don't specify a name, descriptions for all projects are returned.

   ```
   /*
      Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
      SPDX-License-Identifier: Apache-2.0
   */
   
   package com.example.rekognition;
   
   import java.util.ArrayList;
   import java.util.List;
   import java.util.logging.Level;
   import java.util.logging.Logger;
   
   import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
   import software.amazon.awssdk.services.rekognition.RekognitionClient;
   import software.amazon.awssdk.services.rekognition.model.DatasetMetadata;
   import software.amazon.awssdk.services.rekognition.model.DescribeProjectsRequest;
   import software.amazon.awssdk.services.rekognition.model.DescribeProjectsResponse;
   import software.amazon.awssdk.services.rekognition.model.ProjectDescription;
   import software.amazon.awssdk.services.rekognition.model.RekognitionException;
   
   public class DescribeProjects {
   
       public static final Logger logger = Logger.getLogger(DescribeProjects.class.getName());
   
       public static void describeMyProjects(RekognitionClient rekClient, String projectName) {
   
           DescribeProjectsRequest descProjects = null;
   
           // If a single project name is supplied, build projectNames argument
   
           List<String> projectNames = new ArrayList<String>();
   
           if (projectName == null) {
               descProjects = DescribeProjectsRequest.builder().build();
           } else {
               projectNames.add(projectName);
               descProjects = DescribeProjectsRequest.builder().projectNames(projectNames).build();
           }
   
           // Display useful information for each project.
   
           DescribeProjectsResponse resp = rekClient.describeProjects(descProjects);
   
           for (ProjectDescription projectDescription : resp.projectDescriptions()) {
   
               System.out.println("ARN: " + projectDescription.projectArn());
               System.out.println("Status: " + projectDescription.statusAsString());
               if (projectDescription.hasDatasets()) {
                   for (DatasetMetadata datasetDescription : projectDescription.datasets()) {
                       System.out.println("\tdataset Type: " + datasetDescription.datasetTypeAsString());
                       System.out.println("\tdataset ARN: " + datasetDescription.datasetArn());
                       System.out.println("\tdataset Status: " + datasetDescription.statusAsString());
                   }
               }
               System.out.println();
           }
   
       }
   
       public static void main(String[] args) {
   
           String projectArn = null;
   
           // Get command line arguments
   
           final String USAGE = "\n" + "Usage: " + "<project_name>\n\n" + "Where:\n"
                   + "   project_name - (Optional) The name of the project that you want to describe. If not specified, all projects "
                   + "are described.\n\n";
   
           if (args.length > 1) {
               System.out.println(USAGE);
               System.exit(1);
           }
   
           if (args.length == 1) {
               projectArn = args[0];
           }
   
           try {
   
               // Get the Rekognition client
               RekognitionClient rekClient = RekognitionClient.builder()
                   .credentialsProvider(ProfileCredentialsProvider.create("custom-labels-access"))
                   .region(Region.US_WEST_2)
                   .build();
               
               // Describe projects
   
               describeMyProjects(rekClient, projectArn);
   
               rekClient.close();
   
           } catch (RekognitionException rekError) {
               logger.log(Level.SEVERE, "Rekognition client error: {0}", rekError.getMessage());
               System.exit(1);
           }
   
       }
   
   }
   ```

------

# Creating a project with AWS CloudFormation
<a name="cloudformation"></a>

Amazon Rekognition Custom Labels is integrated with AWS CloudFormation, a service that helps you model and set up your AWS resources so that you can spend less time creating and managing your resources and infrastructure. You create a template that describes all the AWS resources that you want, and CloudFormation takes care of provisioning and configuring those resources for you.

You can use CloudFormation to provision and configure Amazon Rekognition Custom Labels projects. 

When you use CloudFormation, you can reuse your template to set up your Amazon Rekognition Custom Labels projects consistently and repeatedly. Just describe your projects once, and then provision the same projects over and over in multiple AWS accounts and Regions. 

## Amazon Rekognition Custom Labels and CloudFormation templates
<a name="working-with-templates"></a>

To provision and configure projects for Amazon Rekognition Custom Labels and related services, you must understand [CloudFormation templates](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-guide.html). Templates are formatted text files in JSON or YAML. These templates describe the resources that you want to provision in your CloudFormation stacks. If you're unfamiliar with JSON or YAML, you can use CloudFormation Designer to help you get started with CloudFormation templates. For more information, see [What is CloudFormation Designer?](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/working-with-templates-cfn-designer.html) in the *AWS CloudFormation User Guide*.

 For reference information about Amazon Rekognition Custom Labels projects, including examples of JSON and YAML templates, see [Rekognition resource type reference](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/AWS_Rekognition.html).

## Learn more about CloudFormation
<a name="learn-more-cloudformation"></a>

To learn more about CloudFormation, see the following resources:
+ [AWS CloudFormation](https://aws.amazon.com/cloudformation/)
+ [AWS CloudFormation User Guide](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)
+ [CloudFormation API Reference](https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/Welcome.html)
+ [AWS CloudFormation Command Line Interface User Guide](https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/what-is-cloudformation-cli.html)