Skip to content

delete_service async

delete_service(
    service: String,
    *,
    config_overrides: Optional[AsyncECSClientConfig] = None,
    cluster: Optional[String] = None,
    force: Optional[BoxedBoolean] = None,
) -> DeleteServiceResponse

Deletes a specified service within a cluster. You can delete a service if you have no running tasks in it and the desired task count is zero. If the service is actively maintaining tasks, you can't delete it, and you must update the service to a desired task count of zero. For more information, see UpdateService.

When you delete a service, if there are still running tasks that require cleanup, the service status moves from ACTIVE to DRAINING, and the service is no longer visible in the console or in the ListServices API operation. After all tasks have transitioned to either STOPPING or STOPPED status, the service status moves from DRAINING to INACTIVE. Services in the DRAINING or INACTIVE status can still be viewed with the DescribeServices API operation. However, in the future, INACTIVE services may be cleaned up and purged from Amazon ECS record keeping, and DescribeServices calls on those services return a ServiceNotFoundException error.

If you attempt to create a new service with the same name as an existing service in either ACTIVE or DRAINING status, you receive an error.

Parameters:

  • cluster (Optional[String], default: None ) –

    The short name or full Amazon Resource Name (ARN) of the cluster that hosts the service to delete. If you do not specify a cluster, the default cluster is assumed.

  • service (String) –

    The name of the service to delete.

  • force (Optional[BoxedBoolean], default: None ) –

    If true, allows you to delete a service even if it wasn't scaled down to zero tasks. It's only necessary to use this if the service uses the REPLICA scheduling strategy.

Raises:

  • AccessDeniedException –

    You don't have authorization to perform the requested action.

  • ClientException –

    These errors are usually caused by a client action. This client action might be using an action or resource on behalf of a user that doesn't have permissions to use the action or resource. Or, it might be specifying an identifier that isn't valid.

  • ClusterNotFoundException –

    The specified cluster wasn't found. You can view your available clusters with ListClusters. Amazon ECS clusters are Region specific.

  • InvalidParameterException –

    The specified parameter isn't valid. Review the available parameters for the API request.

    For more information about service event errors, see Amazon ECS service event messages.

  • ServerException –

    These errors are usually caused by a server issue.

  • ServiceNotFoundException –

    The specified service wasn't found. You can view your available services with ListServices. Amazon ECS services are cluster specific and Region specific.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Examples:

To delete a service This example deletes the my-http-service service. The service must have a desired count and running count of 0 before you can delete it.

>>> await client.delete_service(service='my-http-service')
Source code in docs_src/capo_ecs/_services/async_ecs.py
async def delete_service(
    self,
    service: "capo_ecs.types.string.String",
    *,
    config_overrides: Optional[AsyncECSClientConfig] = None,
    cluster: Optional["capo_ecs.types.string.String"] = None,
    force: Optional["capo_ecs.types.boxed_boolean.BoxedBoolean"] = None,
) -> "capo_ecs.types.delete_service_response.DeleteServiceResponse":
    """<p>Deletes a specified service within a cluster. You can delete a service if you have no running tasks in it and the desired task count is zero. If the service is actively maintaining tasks, you can't delete it, and you must update the service to a desired task count of zero. For more information, see <a href="https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_UpdateService.html">UpdateService</a>.</p> <note> <p>When you delete a service, if there are still running tasks that require cleanup, the service status moves from <code>ACTIVE</code> to <code>DRAINING</code>, and the service is no longer visible in the console or in the <a href="https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ListServices.html">ListServices</a> API operation. After all tasks have transitioned to either <code>STOPPING</code> or <code>STOPPED</code> status, the service status moves from <code>DRAINING</code> to <code>INACTIVE</code>. Services in the <code>DRAINING</code> or <code>INACTIVE</code> status can still be viewed with the <a href="https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DescribeServices.html">DescribeServices</a> API operation. However, in the future, <code>INACTIVE</code> services may be cleaned up and purged from Amazon ECS record keeping, and <a href="https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DescribeServices.html">DescribeServices</a> calls on those services return a <code>ServiceNotFoundException</code> error.</p> </note> <important> <p>If you attempt to create a new service with the same name as an existing service in either <code>ACTIVE</code> or <code>DRAINING</code> status, you receive an error.</p> </important>

    Args:
        cluster: <p>The short name or full Amazon Resource Name (ARN) of the cluster that hosts the service to delete. If you do not specify a cluster, the default cluster is assumed.</p>
        service: <p>The name of the service to delete.</p>
        force: <p>If <code>true</code>, allows you to delete a service even if it wasn't scaled down to zero tasks. It's only necessary to use this if the service uses the <code>REPLICA</code> scheduling strategy.</p>

    Raises:
        capo_ecs.errors.access_denied_exception.AccessDeniedException: <p>You don't have authorization to perform the requested action.</p>
        capo_ecs.errors.client_exception.ClientException: <p>These errors are usually caused by a client action. This client action might be using an action or resource on behalf of a user that doesn't have permissions to use the action or resource. Or, it might be specifying an identifier that isn't valid.</p>
        capo_ecs.errors.cluster_not_found_exception.ClusterNotFoundException: <p>The specified cluster wasn't found. You can view your available clusters with <a href="https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ListClusters.html">ListClusters</a>. Amazon ECS clusters are Region specific.</p>
        capo_ecs.errors.invalid_parameter_exception.InvalidParameterException: <p>The specified parameter isn't valid. Review the available parameters for the API request.</p> <p>For more information about service event errors, see <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-event-messages-list.html">Amazon ECS service event messages</a>. </p>
        capo_ecs.errors.server_exception.ServerException: <p>These errors are usually caused by a server issue.</p>
        capo_ecs.errors.service_not_found_exception.ServiceNotFoundException: <p>The specified service wasn't found. You can view your available services with <a href="https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ListServices.html">ListServices</a>. Amazon ECS services are cluster specific and Region specific.</p>
        capo_ecs.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To delete a service
        This example deletes the my-http-service service. The service must have a desired count and running count of 0 before you can delete it.

        >>> await client.delete_service(service='my-http-service')
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_ecs.types.delete_service_request.DeleteServiceRequest]",
    ) -> AsyncOperationResponse[
        "capo_ecs.types.delete_service_response.DeleteServiceResponse"
    ]:
        import capo_ecs._operations.amazon_ec2_container_service_v20141113.delete_service

        (
            output,
            http_response,
        ) = await capo_ecs._operations.amazon_ec2_container_service_v20141113.delete_service.async_delete_service(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("DeleteService")
    )
    input_: capo_ecs.types.delete_service_request.DeleteServiceRequest = {
        "service": service
    }
    if cluster is not None:
        input_["cluster"] = cluster
    if force is not None:
        input_["force"] = force

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output