Skip to content

update_service

update_service(
    id: Arn,
    service: ServiceChange,
    *,
    config_overrides: Optional[ServiceDiscoveryClientConfig] = None,
) -> UpdateServiceResponse

Submits a request to perform the following operations:

  • Update the TTL setting for existing DnsRecords configurations

  • Add, update, or delete HealthCheckConfig for a specified service

    You can't add, update, or delete a HealthCheckCustomConfig configuration.

For public and private DNS namespaces, note the following:

  • If you omit any existing DnsRecords or HealthCheckConfig configurations from an UpdateService request, the configurations are deleted from the service.

  • If you omit an existing HealthCheckCustomConfig configuration from an UpdateService request, the configuration isn't deleted from the service.

You can't call UpdateService and update settings in the following scenarios:

  • When the service is associated with an HTTP namespace

  • When the service is associated with a shared namespace and contains instances that were registered by Amazon Web Services accounts other than the account making the UpdateService call

When you update settings for a service, Cloud Map also updates the corresponding settings in all the records and health checks that were created by using the specified service.

Parameters:

  • id (Arn) –

    The ID or Amazon Resource Name (ARN) of the service that you want to update. If the namespace associated with the service is shared with your Amazon Web Services account, specify the service ARN. For more information about shared namespaces, see Cross-account Cloud Map namespace sharing in the Cloud Map Developer Guide

  • service (ServiceChange) –

    A complex type that contains the new settings for the service. You can specify a maximum of 30 attributes (key-value pairs).

Raises:

  • DuplicateRequest –

    The operation is already in progress.

  • InvalidInput –

    One or more specified values aren't valid. For example, a required value might be missing, a numeric value might be outside the allowed range, or a string value might exceed length constraints.

  • ServiceNotFound –

    No service exists with the specified ID.

  • UnknownServiceError –

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

Examples:

UpdateService Example This example submits a request to replace the DnsConfig and HealthCheckConfig settings of a specified service.

>>> client.update_service(id='srv-e4anhexample0004', service={'HealthCheckConfig': {'Type': 'HTTP', 'ResourcePath': '/', 'FailureThreshold': 2}, 'DnsConfig': {'DnsRecords': [{'Type': 'A', 'TTL': 60}]}})
Update service using service ARN for shared namespace
This example updates a service using a service ARN instead of service ID. This is useful for updating services associated with shared namespaces.
>>> client.update_service(id='arn:aws:servicediscovery:us-west-2:123456789012:service/srv-e4anhexample0004', service={'Description': 'Updated service description for shared namespace'})
Source code in docs_src/capo_servicediscovery/_services/service_discovery.py
def update_service(
    self,
    id: "capo_servicediscovery.types.arn.Arn",
    service: "capo_servicediscovery.types.service_change.ServiceChange",
    *,
    config_overrides: Optional[ServiceDiscoveryClientConfig] = None,
) -> "capo_servicediscovery.types.update_service_response.UpdateServiceResponse":
    """<p>Submits a request to perform the following operations:</p> <ul> <li> <p>Update the TTL setting for existing <code>DnsRecords</code> configurations</p> </li> <li> <p>Add, update, or delete <code>HealthCheckConfig</code> for a specified service</p> <note> <p>You can't add, update, or delete a <code>HealthCheckCustomConfig</code> configuration.</p> </note> </li> </ul> <p>For public and private DNS namespaces, note the following:</p> <ul> <li> <p>If you omit any existing <code>DnsRecords</code> or <code>HealthCheckConfig</code> configurations from an <code>UpdateService</code> request, the configurations are deleted from the service.</p> </li> <li> <p>If you omit an existing <code>HealthCheckCustomConfig</code> configuration from an <code>UpdateService</code> request, the configuration isn't deleted from the service.</p> </li> </ul> <note> <p>You can't call <code>UpdateService</code> and update settings in the following scenarios:</p> <ul> <li> <p>When the service is associated with an HTTP namespace</p> </li> <li> <p>When the service is associated with a shared namespace and contains instances that were registered by Amazon Web Services accounts other than the account making the <code>UpdateService</code> call</p> </li> </ul> </note> <p>When you update settings for a service, Cloud Map also updates the corresponding settings in all the records and health checks that were created by using the specified service.</p>

    Args:
        id: <p>The ID or Amazon Resource Name (ARN) of the service that you want to update. If the namespace associated with the service is shared with your Amazon Web Services account, specify the service ARN. For more information about shared namespaces, see <a href="https://docs.aws.amazon.com/cloud-map/latest/dg/sharing-namespaces.html">Cross-account Cloud Map namespace sharing</a> in the <i>Cloud Map Developer Guide</i> </p>
        service: <p>A complex type that contains the new settings for the service. You can specify a maximum of 30 attributes (key-value pairs).</p>

    Raises:
        capo_servicediscovery.errors.duplicate_request.DuplicateRequest: <p>The operation is already in progress.</p>
        capo_servicediscovery.errors.invalid_input.InvalidInput: <p>One or more specified values aren't valid. For example, a required value might be missing, a numeric value might be outside the allowed range, or a string value might exceed length constraints.</p>
        capo_servicediscovery.errors.service_not_found.ServiceNotFound: <p>No service exists with the specified ID.</p>
        capo_servicediscovery.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        UpdateService Example
        This example submits a request to replace the DnsConfig and HealthCheckConfig settings of a specified service.

        >>> client.update_service(id='srv-e4anhexample0004', service={'HealthCheckConfig': {'Type': 'HTTP', 'ResourcePath': '/', 'FailureThreshold': 2}, 'DnsConfig': {'DnsRecords': [{'Type': 'A', 'TTL': 60}]}})
        Update service using service ARN for shared namespace
        This example updates a service using a service ARN instead of service ID. This is useful for updating services associated with shared namespaces.

        >>> client.update_service(id='arn:aws:servicediscovery:us-west-2:123456789012:service/srv-e4anhexample0004', service={'Description': 'Updated service description for shared namespace'})
    """

    def _handler(
        req: "OperationRequest[capo_servicediscovery.types.update_service_request.UpdateServiceRequest]",
    ) -> OperationResponse[
        "capo_servicediscovery.types.update_service_response.UpdateServiceResponse"
    ]:
        import capo_servicediscovery._operations.route53_auto_naming_v20170314.update_service

        output, http_response = (
            capo_servicediscovery._operations.route53_auto_naming_v20170314.update_service.update_service(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("UpdateService")
    )
    input_: capo_servicediscovery.types.update_service_request.UpdateServiceRequest = {
        "id": id,
        "service": service,
    }

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output