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 -
AandAAAA -
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
SRVrecord when you register an instance and you're using a system that requires a specificSRVformat, such as HAProxy, specify the following forName:-
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
SRVrecord 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
CreateServicerequests to be retried without the risk of running the operation twice.CreatorRequestIdcan 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
HealthCheckCustomConfigorHealthCheckConfigbut 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
HealthCheckCustomConfigorHealthCheckConfigbut not both.You can't add, update, or delete a
HealthCheckCustomConfigconfiguration 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
DiscoverInstancesAPI operation. No DNS records is registered for the service instances. The only valid value isHTTP.
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
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 | |