:doc:`ECS <../../ecs>` / Client / delete_cluster

**************
delete_cluster
**************



.. py:method:: ECS.Client.delete_cluster(**kwargs)

  

  Deletes the specified cluster. The cluster transitions to the ``INACTIVE`` state. Clusters with an ``INACTIVE`` status might remain discoverable in your account for a period of time. However, this behavior is subject to change in the future. We don't recommend that you rely on ``INACTIVE`` clusters persisting.

   

  You must deregister all container instances from this cluster before you may delete it. You can list the container instances in a cluster with `ListContainerInstances <https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ListContainerInstances.html>`__ and deregister them with `DeregisterContainerInstance <https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DeregisterContainerInstance.html>`__.

  

  See also: `AWS API Documentation <https://docs.aws.amazon.com/goto/WebAPI/ecs-2014-11-13/DeleteCluster>`_  


  **Request Syntax**
  ::

    response = client.delete_cluster(
        cluster='string'
    )
    
  :type cluster: string
  :param cluster: **[REQUIRED]** 

    The short name or full Amazon Resource Name (ARN) of the cluster to delete.

    

  
  
  :rtype: dict
  :returns: 
    
    **Response Syntax**

    
    ::

      {
          'cluster': {
              'clusterArn': 'string',
              'clusterName': 'string',
              'configuration': {
                  'executeCommandConfiguration': {
                      'kmsKeyId': 'string',
                      'logging': 'NONE'|'DEFAULT'|'OVERRIDE',
                      'logConfiguration': {
                          'cloudWatchLogGroupName': 'string',
                          'cloudWatchEncryptionEnabled': True|False,
                          's3BucketName': 'string',
                          's3EncryptionEnabled': True|False,
                          's3KeyPrefix': 'string'
                      }
                  },
                  'managedStorageConfiguration': {
                      'kmsKeyId': 'string',
                      'fargateEphemeralStorageKmsKeyId': 'string'
                  }
              },
              'status': 'string',
              'registeredContainerInstancesCount': 123,
              'runningTasksCount': 123,
              'pendingTasksCount': 123,
              'activeServicesCount': 123,
              'statistics': [
                  {
                      'name': 'string',
                      'value': 'string'
                  },
              ],
              'tags': [
                  {
                      'key': 'string',
                      'value': 'string'
                  },
              ],
              'settings': [
                  {
                      'name': 'containerInsights',
                      'value': 'string'
                  },
              ],
              'capacityProviders': [
                  'string',
              ],
              'defaultCapacityProviderStrategy': [
                  {
                      'capacityProvider': 'string',
                      'weight': 123,
                      'base': 123
                  },
              ],
              'attachments': [
                  {
                      'id': 'string',
                      'type': 'string',
                      'status': 'string',
                      'details': [
                          {
                              'name': 'string',
                              'value': 'string'
                          },
                      ]
                  },
              ],
              'attachmentsStatus': 'string',
              'serviceConnectDefaults': {
                  'namespace': 'string'
              }
          }
      }
      
    **Response Structure**

    

    - *(dict) --* 
      

      - **cluster** *(dict) --* 

        The full description of the deleted cluster.

        
        

        - **clusterArn** *(string) --* 

          The Amazon Resource Name (ARN) that identifies the cluster. For more information about the ARN format, see `Amazon Resource Name (ARN) <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-account-settings.html#ecs-resource-ids>`__ in the *Amazon ECS Developer Guide*.

          
        

        - **clusterName** *(string) --* 

          A user-generated string that you use to identify your cluster.

          
        

        - **configuration** *(dict) --* 

          The execute command and managed storage configuration for the cluster.

          
          

          - **executeCommandConfiguration** *(dict) --* 

            The details of the execute command configuration.

            
            

            - **kmsKeyId** *(string) --* 

              Specify an Key Management Service key ID to encrypt the data between the local client and the container.

              
            

            - **logging** *(string) --* 

              The log setting to use for redirecting logs for your execute command results. The following log settings are available.

               

              
              * ``NONE``: The execute command session is not logged.
               
              * ``DEFAULT``: The ``awslogs`` configuration in the task definition is used. If no logging parameter is specified, it defaults to this value. If no ``awslogs`` log driver is configured in the task definition, the output won't be logged.
               
              * ``OVERRIDE``: Specify the logging details as a part of ``logConfiguration``. If the ``OVERRIDE`` logging option is specified, the ``logConfiguration`` is required.
              

              
            

            - **logConfiguration** *(dict) --* 

              The log configuration for the results of the execute command actions. The logs can be sent to CloudWatch Logs or an Amazon S3 bucket. When ``logging=OVERRIDE`` is specified, a ``logConfiguration`` must be provided.

              
              

              - **cloudWatchLogGroupName** *(string) --* 

                The name of the CloudWatch log group to send logs to.

                 

                .. note::

                  

                  The CloudWatch log group must already be created.

                  

                
              

              - **cloudWatchEncryptionEnabled** *(boolean) --* 

                Determines whether to use encryption on the CloudWatch logs. If not specified, encryption will be off.

                
              

              - **s3BucketName** *(string) --* 

                The name of the S3 bucket to send logs to.

                 

                .. note::

                  

                  The S3 bucket must already be created.

                  

                
              

              - **s3EncryptionEnabled** *(boolean) --* 

                Determines whether to use encryption on the S3 logs. If not specified, encryption is not used.

                
              

              - **s3KeyPrefix** *(string) --* 

                An optional folder in the S3 bucket to place logs in.

                
          
        
          

          - **managedStorageConfiguration** *(dict) --* 

            The details of the managed storage configuration.

            
            

            - **kmsKeyId** *(string) --* 

              Specify a Key Management Service key ID to encrypt Amazon ECS managed storage.

               

              When you specify a ``kmsKeyId``, Amazon ECS uses the key to encrypt data volumes managed by Amazon ECS that are attached to tasks in the cluster. The following data volumes are managed by Amazon ECS: Amazon EBS. For more information about encryption of Amazon EBS volumes attached to Amazon ECS tasks, see `Encrypt data stored in Amazon EBS volumes for Amazon ECS <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ebs-kms-encryption.html>`__ in the *Amazon Elastic Container Service Developer Guide*.

               

              The key must be a single Region key.

              
            

            - **fargateEphemeralStorageKmsKeyId** *(string) --* 

              Specify the Key Management Service key ID for Fargate ephemeral storage.

               

              When you specify a ``fargateEphemeralStorageKmsKeyId``, Amazon Web Services Fargate uses the key to encrypt data at rest in ephemeral storage. For more information about Fargate ephemeral storage encryption, see `Customer managed keys for Amazon Web Services Fargate ephemeral storage for Amazon ECS <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/fargate-storage-encryption.html>`__ in the *Amazon Elastic Container Service Developer Guide*.

               

              The key must be a single Region key.

              
        
      
        

        - **status** *(string) --* 

          The status of the cluster. The following are the possible states that are returned.

            ACTIVE  

          The cluster is ready to accept tasks and if applicable you can register container instances with the cluster.

            PROVISIONING  

          The cluster has capacity providers that are associated with it and the resources needed for the capacity provider are being created.

            DEPROVISIONING  

          The cluster has capacity providers that are associated with it and the resources needed for the capacity provider are being deleted.

            FAILED  

          The cluster has capacity providers that are associated with it and the resources needed for the capacity provider have failed to create.

            INACTIVE  

          The cluster has been deleted. Clusters with an ``INACTIVE`` status may remain discoverable in your account for a period of time. However, this behavior is subject to change in the future. We don't recommend that you rely on ``INACTIVE`` clusters persisting.

          
        

        - **registeredContainerInstancesCount** *(integer) --* 

          The number of container instances registered into the cluster. This includes container instances in both ``ACTIVE`` and ``DRAINING`` status.

          
        

        - **runningTasksCount** *(integer) --* 

          The number of tasks in the cluster that are in the ``RUNNING`` state.

          
        

        - **pendingTasksCount** *(integer) --* 

          The number of tasks in the cluster that are in the ``PENDING`` state.

          
        

        - **activeServicesCount** *(integer) --* 

          The number of services that are running on the cluster in an ``ACTIVE`` state. You can view these services with `ListServices <https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ListServices.html>`__.

          
        

        - **statistics** *(list) --* 

          Additional information about your clusters that are separated by launch type. They include the following:

           

          
          * runningEC2TasksCount
           
          * RunningFargateTasksCount
           
          * pendingEC2TasksCount
           
          * pendingFargateTasksCount
           
          * activeEC2ServiceCount
           
          * activeFargateServiceCount
           
          * drainingEC2ServiceCount
           
          * drainingFargateServiceCount
          

          
          

          - *(dict) --* 

            A key-value pair object.

            
            

            - **name** *(string) --* 

              The name of the key-value pair. For environment variables, this is the name of the environment variable.

              
            

            - **value** *(string) --* 

              The value of the key-value pair. For environment variables, this is the value of the environment variable.

              
        
      
        

        - **tags** *(list) --* 

          The metadata that you apply to the cluster to help you categorize and organize them. Each tag consists of a key and an optional value. You define both.

           

          The following basic restrictions apply to tags:

           

          
          * Maximum number of tags per resource - 50
           
          * For each resource, each tag key must be unique, and each tag key can have only one value.
           
          * Maximum key length - 128 Unicode characters in UTF-8
           
          * Maximum value length - 256 Unicode characters in UTF-8
           
          * If your tagging schema is used across multiple services and resources, remember that other services may have restrictions on allowed characters. Generally allowed characters are: letters, numbers, and spaces representable in UTF-8, and the following characters: + - = . _ : / @.
           
          * Tag keys and values are case-sensitive.
           
          * Do not use ``aws:``, ``AWS:``, or any upper or lowercase combination of such as a prefix for either keys or values as it is reserved for Amazon Web Services use. You cannot edit or delete tag keys or values with this prefix. Tags with this prefix do not count against your tags per resource limit.
          

          
          

          - *(dict) --* 

            The metadata that you apply to a resource to help you categorize and organize them. Each tag consists of a key and an optional value. You define them.

             

            The following basic restrictions apply to tags:

             

            
            * Maximum number of tags per resource - 50
             
            * For each resource, each tag key must be unique, and each tag key can have only one value.
             
            * Maximum key length - 128 Unicode characters in UTF-8
             
            * Maximum value length - 256 Unicode characters in UTF-8
             
            * If your tagging schema is used across multiple services and resources, remember that other services may have restrictions on allowed characters. Generally allowed characters are: letters, numbers, and spaces representable in UTF-8, and the following characters: + - = . _ : / @.
             
            * Tag keys and values are case-sensitive.
             
            * Do not use ``aws:``, ``AWS:``, or any upper or lowercase combination of such as a prefix for either keys or values as it is reserved for Amazon Web Services use. You cannot edit or delete tag keys or values with this prefix. Tags with this prefix do not count against your tags per resource limit.
            

            
            

            - **key** *(string) --* 

              One part of a key-value pair that make up a tag. A ``key`` is a general label that acts like a category for more specific tag values.

              
            

            - **value** *(string) --* 

              The optional part of a key-value pair that make up a tag. A ``value`` acts as a descriptor within a tag category (key).

              
        
      
        

        - **settings** *(list) --* 

          The settings for the cluster. This parameter indicates whether CloudWatch Container Insights is on or off for a cluster.

          
          

          - *(dict) --* 

            The settings to use when creating a cluster. This parameter is used to turn on CloudWatch Container Insights with enhanced observability or CloudWatch Container Insights for a cluster.

             

            Container Insights with enhanced observability provides all the Container Insights metrics, plus additional task and container metrics. This version supports enhanced observability for Amazon ECS clusters using the Amazon EC2 and Fargate launch types. After you configure Container Insights with enhanced observability on Amazon ECS, Container Insights auto-collects detailed infrastructure telemetry from the cluster level down to the container level in your environment and displays these critical performance data in curated dashboards removing the heavy lifting in observability set-up.

             

            For more information, see `Monitor Amazon ECS containers using Container Insights with enhanced observability <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cloudwatch-container-insights.html>`__ in the *Amazon Elastic Container Service Developer Guide*.

            
            

            - **name** *(string) --* 

              The name of the cluster setting. The value is ``containerInsights``.

              
            

            - **value** *(string) --* 

              The value to set for the cluster setting. The supported values are ``enhanced``, ``enabled``, and ``disabled``.

               

              To use Container Insights with enhanced observability, set the ``containerInsights`` account setting to ``enhanced``.

               

              To use Container Insights, set the ``containerInsights`` account setting to ``enabled``.

               

              If a cluster value is specified, it will override the ``containerInsights`` value set with `PutAccountSetting <https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_PutAccountSetting.html>`__ or `PutAccountSettingDefault <https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_PutAccountSettingDefault.html>`__.

              
        
      
        

        - **capacityProviders** *(list) --* 

          The capacity providers associated with the cluster.

          
          

          - *(string) --* 
      
        

        - **defaultCapacityProviderStrategy** *(list) --* 

          The default capacity provider strategy for the cluster. When services or tasks are run in the cluster with no launch type or capacity provider strategy specified, the default capacity provider strategy is used.

          
          

          - *(dict) --* 

            The details of a capacity provider strategy. A capacity provider strategy can be set when using the `RunTask <https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_RunTask.html>`__or `CreateCluster <https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_CreateCluster.html>`__ APIs or as the default capacity provider strategy for a cluster with the ``CreateCluster`` API.

             

            Only capacity providers that are already associated with a cluster and have an ``ACTIVE`` or ``UPDATING`` status can be used in a capacity provider strategy. The `PutClusterCapacityProviders <https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_PutClusterCapacityProviders.html>`__ API is used to associate a capacity provider with a cluster.

             

            If specifying a capacity provider that uses an Auto Scaling group, the capacity provider must already be created. New Auto Scaling group capacity providers can be created with the `CreateClusterCapacityProvider <https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_CreateClusterCapacityProvider.html>`__ API operation.

             

            To use a Fargate capacity provider, specify either the ``FARGATE`` or ``FARGATE_SPOT`` capacity providers. The Fargate capacity providers are available to all accounts and only need to be associated with a cluster to be used in a capacity provider strategy.

             

            With ``FARGATE_SPOT``, you can run interruption tolerant tasks at a rate that's discounted compared to the ``FARGATE`` price. ``FARGATE_SPOT`` runs tasks on spare compute capacity. When Amazon Web Services needs the capacity back, your tasks are interrupted with a two-minute warning. ``FARGATE_SPOT`` supports Linux tasks with the X86_64 architecture on platform version 1.3.0 or later. ``FARGATE_SPOT`` supports Linux tasks with the ARM64 architecture on platform version 1.4.0 or later.

             

            A capacity provider strategy can contain a maximum of 20 capacity providers.

            
            

            - **capacityProvider** *(string) --* 

              The short name of the capacity provider.

              
            

            - **weight** *(integer) --* 

              The *weight* value designates the relative percentage of the total number of tasks launched that should use the specified capacity provider. The ``weight`` value is taken into consideration after the ``base`` value, if defined, is satisfied.

               

              If no ``weight`` value is specified, the default value of ``0`` is used. When multiple capacity providers are specified within a capacity provider strategy, at least one of the capacity providers must have a weight value greater than zero and any capacity providers with a weight of ``0`` can't be used to place tasks. If you specify multiple capacity providers in a strategy that all have a weight of ``0``, any ``RunTask`` or ``CreateService`` actions using the capacity provider strategy will fail.

               

              Weight value characteristics:

               

              
              * Weight is considered after the base value is satisfied
               
              * The default value is ``0`` if not specified
               
              * The valid range is 0 to 1,000
               
              * At least one capacity provider must have a weight greater than zero
               
              * Capacity providers with weight of ``0`` cannot place tasks
              

               

              Task distribution logic:

               

               
              * Base satisfaction: The minimum number of tasks specified by the base value are placed on that capacity provider
               
              * Weight distribution: After base requirements are met, additional tasks are distributed according to weight ratios
               

               

              Examples:

               

              Equal Distribution: Two capacity providers both with weight ``1`` will split tasks evenly after base requirements are met.

               

              Weighted Distribution: If capacityProviderA has weight ``1`` and capacityProviderB has weight ``4``, then for every 1 task on A, 4 tasks will run on B.

              
            

            - **base** *(integer) --* 

              The *base* value designates how many tasks, at a minimum, to run on the specified capacity provider for each service. Only one capacity provider in a capacity provider strategy can have a *base* defined. If no value is specified, the default value of ``0`` is used.

               

              Base value characteristics:

               

              
              * Only one capacity provider in a strategy can have a base defined
               
              * The default value is ``0`` if not specified
               
              * The valid range is 0 to 100,000
               
              * Base requirements are satisfied first before weight distribution
              

              
        
      
        

        - **attachments** *(list) --* 

          The resources attached to a cluster. When using a capacity provider with a cluster, the capacity provider and associated resources are returned as cluster attachments.

          
          

          - *(dict) --* 

            An object representing a container instance or task attachment.

            
            

            - **id** *(string) --* 

              The unique identifier for the attachment.

              
            

            - **type** *(string) --* 

              The type of the attachment, such as ``ElasticNetworkInterface``, ``Service Connect``, and ``AmazonElasticBlockStorage``.

              
            

            - **status** *(string) --* 

              The status of the attachment. Valid values are ``PRECREATED``, ``CREATED``, ``ATTACHING``, ``ATTACHED``, ``DETACHING``, ``DETACHED``, ``DELETED``, and ``FAILED``.

              
            

            - **details** *(list) --* 

              Details of the attachment.

               

              For elastic network interfaces, this includes the network interface ID, the MAC address, the subnet ID, and the private IPv4 address.

               

              For Service Connect services, this includes ``portName``, ``clientAliases``, ``discoveryName``, and ``ingressPortOverride``.

               

              For Elastic Block Storage, this includes ``roleArn``, ``deleteOnTermination``, ``volumeName``, ``volumeId``, and ``statusReason`` (only when the attachment fails to create or attach).

              
              

              - *(dict) --* 

                A key-value pair object.

                
                

                - **name** *(string) --* 

                  The name of the key-value pair. For environment variables, this is the name of the environment variable.

                  
                

                - **value** *(string) --* 

                  The value of the key-value pair. For environment variables, this is the value of the environment variable.

                  
            
          
        
      
        

        - **attachmentsStatus** *(string) --* 

          The status of the capacity providers associated with the cluster. The following are the states that are returned.

            UPDATE_IN_PROGRESS  

          The available capacity providers for the cluster are updating.

            UPDATE_COMPLETE  

          The capacity providers have successfully updated.

            UPDATE_FAILED  

          The capacity provider updates failed.

          
        

        - **serviceConnectDefaults** *(dict) --* 

          Use this parameter to set a default Service Connect namespace. After you set a default Service Connect namespace, any new services with Service Connect turned on that are created in the cluster are added as client services in the namespace. This setting only applies to new services that set the ``enabled`` parameter to ``true`` in the ``ServiceConnectConfiguration``. You can set the namespace of each service individually in the ``ServiceConnectConfiguration`` to override this default parameter.

           

          Tasks that run in a namespace can use short names to connect to services in the namespace. Tasks can connect to services across all of the clusters in the namespace. Tasks connect through a managed proxy container that collects logs and metrics for increased visibility. Only the tasks that Amazon ECS services create are supported with Service Connect. For more information, see `Service Connect <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-connect.html>`__ in the *Amazon Elastic Container Service Developer Guide*.

          
          

          - **namespace** *(string) --* 

            The namespace name or full Amazon Resource Name (ARN) of the Cloud Map namespace. When you create a service and don't specify a Service Connect configuration, this namespace is used.

            
      
    
  
  **Exceptions**
  
  *   :py:class:`ECS.Client.exceptions.ServerException`

  
  *   :py:class:`ECS.Client.exceptions.ClientException`

  
  *   :py:class:`ECS.Client.exceptions.InvalidParameterException`

  
  *   :py:class:`ECS.Client.exceptions.ClusterNotFoundException`

  
  *   :py:class:`ECS.Client.exceptions.ClusterContainsCapacityProviderException`

  
  *   :py:class:`ECS.Client.exceptions.ClusterContainsContainerInstancesException`

  
  *   :py:class:`ECS.Client.exceptions.ClusterContainsServicesException`

  
  *   :py:class:`ECS.Client.exceptions.ClusterContainsTasksException`

  
  *   :py:class:`ECS.Client.exceptions.UpdateInProgressException`

  

  **Examples**

  This example deletes an empty cluster in your default region.
  ::

    response = client.delete_cluster(
        cluster='my_cluster',
    )
    
    print(response)

  
  Expected Output:
  ::

    {
        'cluster': {
            'activeServicesCount': 0,
            'clusterArn': 'arn:aws:ecs:us-east-1:012345678910:cluster/my_cluster',
            'clusterName': 'my_cluster',
            'pendingTasksCount': 0,
            'registeredContainerInstancesCount': 0,
            'runningTasksCount': 0,
            'status': 'INACTIVE',
        },
        'ResponseMetadata': {
            '...': '...',
        },
    }

  