Skip to content

create_service async

create_service(
    name: ServiceName,
    *,
    config_overrides: Optional[AsyncServiceDiscoveryClientConfig] = None,
    namespace_id: Optional[Arn] = None,
    creator_request_id: Optional[ResourceId] = None,
    description: Optional[ResourceDescription] = None,
    dns_config: Optional[DnsConfig] = None,
    health_check_config: Optional[HealthCheckConfig] = None,
    health_check_custom_config: Optional[HealthCheckCustomConfig] = None,
    tags: Optional[TagList] = None,
    type: Optional[ServiceTypeOption] = None,
) -> CreateServiceResponse

Creates a service. This action defines the configuration for the following entities:

  • For public and private DNS namespaces, one of the following combinations of DNS records in Amazon Route 53:

    • A

    • AAAA

    • A and AAAA

    • SRV

    • CNAME

  • Optionally, a health check

After you create the service, you can submit a RegisterInstance request, and Cloud Map uses the values in the configuration to create the specified entities.

For the current quota on the number of instances that you can register using the same namespace and using the same service, see Cloud Map quotas in the Cloud Map Developer Guide.

Parameters:

  • name (ServiceName) –

    The name that you want to assign to the service.

    Do not include sensitive information in the name if the namespace is discoverable by public DNS queries.

    If you want Cloud Map to create an SRV record when you register an instance and you're using a system that requires a specific SRV format, such as HAProxy, specify the following for Name:

    • Start the name with an underscore (_), such as _exampleservice.

    • End the name with ._protocol, such as ._tcp.

    When you register an instance, Cloud Map creates an SRV record and assigns a name to the record by concatenating the service name and the namespace name (for example,

    _exampleservice._tcp.example.com).

    For services that are accessible by DNS queries, you can't create multiple services with names that differ only by case (such as EXAMPLE and example). Otherwise, these services have the same DNS name and can't be distinguished. However, if you use a namespace that's only accessible by API calls, then you can create services that with names that differ only by case.

  • namespace_id (Optional[Arn], default: None ) –

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

  • creator_request_id (Optional[ResourceId], default: None ) –

    A unique string that identifies the request and that allows failed CreateService requests to be retried without the risk of running the operation twice. CreatorRequestId can be any unique string (for example, a date/timestamp).

  • description (Optional[ResourceDescription], default: None ) –

    A description for the service.

  • dns_config (Optional[DnsConfig], default: None ) –

    A complex type that contains information about the Amazon Route 53 records that you want Cloud Map to create when you register an instance.

  • health_check_config (Optional[HealthCheckConfig], default: None ) –

    Public DNS and HTTP namespaces only. A complex type that contains settings for an optional Route 53 health check. If you specify settings for a health check, Cloud Map associates the health check with all the Route 53 DNS records that you specify in DnsConfig.

    If you specify a health check configuration, you can specify either HealthCheckCustomConfig or HealthCheckConfig but not both.

    For information about the charges for health checks, see Cloud Map Pricing.

  • health_check_custom_config (Optional[HealthCheckCustomConfig], default: None ) –

    A complex type that contains information about an optional custom health check.

    If you specify a health check configuration, you can specify either HealthCheckCustomConfig or HealthCheckConfig but not both.

    You can't add, update, or delete a HealthCheckCustomConfig configuration from an existing service.

  • tags (Optional[TagList], default: None ) –

    The tags to add to the service. Each tag consists of a key and an optional value that you define. Tags keys can be up to 128 characters in length, and tag values can be up to 256 characters in length.

  • type (Optional[ServiceTypeOption], default: None ) –

    If present, specifies that the service instances are only discoverable using the DiscoverInstances API operation. No DNS records is registered for the service instances. The only valid value is HTTP.

Raises:

  • 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.

  • NamespaceNotFound –

    No namespace exists with the specified ID.

  • ResourceLimitExceeded –

    The resource can't be created because you've reached the quota on the number of resources.

  • ServiceAlreadyExists –

    The service can't be created because a service with the same name already exists.

  • TooManyTagsException –

    The list of tags on the resource is over the quota. The maximum number of tags that can be applied to a resource is 50.

  • UnknownServiceError –

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

Examples:

Example: Create service Example: Create service

>>> await client.create_service(name='myservice', namespace_id='ns-ylexjili4cdxy3xm', dns_config={'NamespaceId': 'ns-ylexjili4cdxy3xm', 'RoutingPolicy': 'MULTIVALUE', 'DnsRecords': [{'Type': 'A', 'TTL': 60}]}, creator_request_id='567c1193-6b00-4308-bd57-ad38a8822d25')
Create service using namespace ARN
Namespace sharee creates a service using a namespace ARN instead of namespace ID, useful when working with shared namespaces.
>>> await client.create_service(name='example-service', namespace_id='arn:aws:servicediscovery:us-west-2:123456789012:namespace/ns-abcd1234xmpl5678', description='Example service using namespace ARN', dns_config={'DnsRecords': [{'Type': 'A', 'TTL': 300}], 'RoutingPolicy': 'MULTIVALUE'})
Source code in docs_src/capo_servicediscovery/_services/async_service_discovery.py
async def create_service(
    self,
    name: "capo_servicediscovery.types.service_name.ServiceName",
    *,
    config_overrides: Optional[AsyncServiceDiscoveryClientConfig] = None,
    namespace_id: Optional["capo_servicediscovery.types.arn.Arn"] = None,
    creator_request_id: Optional[
        "capo_servicediscovery.types.resource_id.ResourceId"
    ] = None,
    description: Optional[
        "capo_servicediscovery.types.resource_description.ResourceDescription"
    ] = None,
    dns_config: Optional["capo_servicediscovery.types.dns_config.DnsConfig"] = None,
    health_check_config: Optional[
        "capo_servicediscovery.types.health_check_config.HealthCheckConfig"
    ] = None,
    health_check_custom_config: Optional[
        "capo_servicediscovery.types.health_check_custom_config.HealthCheckCustomConfig"
    ] = None,
    tags: Optional["capo_servicediscovery.types.tag_list.TagList"] = None,
    type: Optional[
        "capo_servicediscovery.types.service_type_option.ServiceTypeOption"
    ] = None,
) -> "capo_servicediscovery.types.create_service_response.CreateServiceResponse":
    """<p>Creates a service. This action defines the configuration for the following entities:</p> <ul> <li> <p>For public and private DNS namespaces, one of the following combinations of DNS records in Amazon Route 53:</p> <ul> <li> <p> <code>A</code> </p> </li> <li> <p> <code>AAAA</code> </p> </li> <li> <p> <code>A</code> and <code>AAAA</code> </p> </li> <li> <p> <code>SRV</code> </p> </li> <li> <p> <code>CNAME</code> </p> </li> </ul> </li> <li> <p>Optionally, a health check</p> </li> </ul> <p>After you create the service, you can submit a <a href="https://docs.aws.amazon.com/cloud-map/latest/api/API_RegisterInstance.html">RegisterInstance</a> request, and Cloud Map uses the values in the configuration to create the specified entities.</p> <p>For the current quota on the number of instances that you can register using the same namespace and using the same service, see <a href="https://docs.aws.amazon.com/cloud-map/latest/dg/cloud-map-limits.html">Cloud Map quotas</a> in the <i>Cloud Map Developer Guide</i>.</p>

    Args:
        name: <p>The name that you want to assign to the service.</p> <note> <p>Do not include sensitive information in the name if the namespace is discoverable by public DNS queries.</p> </note> <p>If you want Cloud Map to create an <code>SRV</code> record when you register an instance and you're using a system that requires a specific <code>SRV</code> format, such as <a href="http://www.haproxy.org/">HAProxy</a>, specify the following for <code>Name</code>:</p> <ul> <li> <p>Start the name with an underscore (_), such as <code>_exampleservice</code>.</p> </li> <li> <p>End the name with <i>._protocol</i>, such as <code>._tcp</code>.</p> </li> </ul> <p>When you register an instance, Cloud Map creates an <code>SRV</code> record and assigns a name to the record by concatenating the service name and the namespace name (for example,</p> <p> <code>_exampleservice._tcp.example.com</code>).</p> <note> <p>For services that are accessible by DNS queries, you can't create multiple services with names that differ only by case (such as EXAMPLE and example). Otherwise, these services have the same DNS name and can't be distinguished. However, if you use a namespace that's only accessible by API calls, then you can create services that with names that differ only by case.</p> </note>
        namespace_id: <p>The ID or Amazon Resource Name (ARN) of the namespace that you want to use to create the service. For namespaces shared with your Amazon Web Services account, specify the namespace 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>
        creator_request_id: <p>A unique string that identifies the request and that allows failed <code>CreateService</code> requests to be retried without the risk of running the operation twice. <code>CreatorRequestId</code> can be any unique string (for example, a date/timestamp).</p>
        description: <p>A description for the service.</p>
        dns_config: <p>A complex type that contains information about the Amazon Route 53 records that you want Cloud Map to create when you register an instance. </p>
        health_check_config: <p> <i>Public DNS and HTTP namespaces only.</i> A complex type that contains settings for an optional Route 53 health check. If you specify settings for a health check, Cloud Map associates the health check with all the Route 53 DNS records that you specify in <code>DnsConfig</code>.</p> <important> <p>If you specify a health check configuration, you can specify either <code>HealthCheckCustomConfig</code> or <code>HealthCheckConfig</code> but not both.</p> </important> <p>For information about the charges for health checks, see <a href="http://aws.amazon.com/cloud-map/pricing/">Cloud Map Pricing</a>.</p>
        health_check_custom_config: <p>A complex type that contains information about an optional custom health check.</p> <important> <p>If you specify a health check configuration, you can specify either <code>HealthCheckCustomConfig</code> or <code>HealthCheckConfig</code> but not both.</p> </important> <p>You can't add, update, or delete a <code>HealthCheckCustomConfig</code> configuration from an existing service.</p>
        tags: <p>The tags to add to the service. Each tag consists of a key and an optional value that you define. Tags keys can be up to 128 characters in length, and tag values can be up to 256 characters in length.</p>
        type: <p>If present, specifies that the service instances are only discoverable using the <code>DiscoverInstances</code> API operation. No DNS records is registered for the service instances. The only valid value is <code>HTTP</code>.</p>

    Raises:
        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.namespace_not_found.NamespaceNotFound: <p>No namespace exists with the specified ID.</p>
        capo_servicediscovery.errors.resource_limit_exceeded.ResourceLimitExceeded: <p>The resource can't be created because you've reached the quota on the number of resources.</p>
        capo_servicediscovery.errors.service_already_exists.ServiceAlreadyExists: <p>The service can't be created because a service with the same name already exists.</p>
        capo_servicediscovery.errors.too_many_tags_exception.TooManyTagsException: <p>The list of tags on the resource is over the quota. The maximum number of tags that can be applied to a resource is 50.</p>
        capo_servicediscovery.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        Example: Create service
        Example: Create service

        >>> await client.create_service(name='myservice', namespace_id='ns-ylexjili4cdxy3xm', dns_config={'NamespaceId': 'ns-ylexjili4cdxy3xm', 'RoutingPolicy': 'MULTIVALUE', 'DnsRecords': [{'Type': 'A', 'TTL': 60}]}, creator_request_id='567c1193-6b00-4308-bd57-ad38a8822d25')
        Create service using namespace ARN
        Namespace sharee creates a service using a namespace ARN instead of namespace ID, useful when working with shared namespaces.

        >>> await client.create_service(name='example-service', namespace_id='arn:aws:servicediscovery:us-west-2:123456789012:namespace/ns-abcd1234xmpl5678', description='Example service using namespace ARN', dns_config={'DnsRecords': [{'Type': 'A', 'TTL': 300}], 'RoutingPolicy': 'MULTIVALUE'})
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_servicediscovery.types.create_service_request.CreateServiceRequest]",
    ) -> AsyncOperationResponse[
        "capo_servicediscovery.types.create_service_response.CreateServiceResponse"
    ]:
        import capo_servicediscovery._operations.route53_auto_naming_v20170314.create_service

        (
            output,
            http_response,
        ) = await capo_servicediscovery._operations.route53_auto_naming_v20170314.create_service.async_create_service(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateService")
    )
    input_: capo_servicediscovery.types.create_service_request.CreateServiceRequest = {
        "name": name
    }
    if namespace_id is not None:
        input_["namespace_id"] = namespace_id
    if creator_request_id is None:
        creator_request_id = str(uuid.uuid4())
    input_["creator_request_id"] = creator_request_id
    if description is not None:
        input_["description"] = description
    if dns_config is not None:
        input_["dns_config"] = dns_config
    if health_check_config is not None:
        input_["health_check_config"] = health_check_config
    if health_check_custom_config is not None:
        input_["health_check_custom_config"] = health_check_custom_config
    if tags is not None:
        input_["tags"] = tags
    if type is not None:
        input_["type"] = type

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