createService method

Future<CreateServiceResponse> createService({
  1. required String name,
  2. String? creatorRequestId,
  3. String? description,
  4. DnsConfig? dnsConfig,
  5. HealthCheckConfig? healthCheckConfig,
  6. HealthCheckCustomConfig? healthCheckCustomConfig,
  7. String? namespaceId,
  8. List<Tag>? tags,
  9. ServiceTypeOption? type,
})

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.

May throw InvalidInput. May throw NamespaceNotFound. May throw ResourceLimitExceeded. May throw ServiceAlreadyExists. May throw TooManyTagsException.

Parameter name : The name that you want to assign to the service. 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).

Parameter creatorRequestId : 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).

Parameter description : A description for the service.

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

Parameter healthCheckConfig : 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. For information about the charges for health checks, see Cloud Map Pricing.

Parameter healthCheckCustomConfig : A complex type that contains information about an optional custom health check. You can't add, update, or delete a HealthCheckCustomConfig configuration from an existing service.

Parameter namespaceId : 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.

Parameter tags : 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.

Parameter type : 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.

Implementation

Future<CreateServiceResponse> createService({
  required String name,
  String? creatorRequestId,
  String? description,
  DnsConfig? dnsConfig,
  HealthCheckConfig? healthCheckConfig,
  HealthCheckCustomConfig? healthCheckCustomConfig,
  String? namespaceId,
  List<Tag>? tags,
  ServiceTypeOption? type,
}) async {
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'Route53AutoNaming_v20170314.CreateService'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'Name': name,
      'CreatorRequestId': creatorRequestId ?? _s.generateIdempotencyToken(),
      if (description != null) 'Description': description,
      if (dnsConfig != null) 'DnsConfig': dnsConfig,
      if (healthCheckConfig != null) 'HealthCheckConfig': healthCheckConfig,
      if (healthCheckCustomConfig != null)
        'HealthCheckCustomConfig': healthCheckCustomConfig,
      if (namespaceId != null) 'NamespaceId': namespaceId,
      if (tags != null) 'Tags': tags,
      if (type != null) 'Type': type.value,
    },
  );

  return CreateServiceResponse.fromJson(jsonResponse.body);
}