# Amazon ECS Service Discovery Construct Library

This module is part of the [AWS Cloud Development Kit](https://github.com/aws/aws-cdk) project.

This package contains constructs for working with **AWS Cloud Map**

AWS Cloud Map is a fully managed service that you can use to create and
maintain a map of the backend services and resources that your applications
depend on.

For further information on AWS Cloud Map,
see the [AWS Cloud Map documentation](https://docs.aws.amazon.com/cloud-map)

## HTTP Namespace Example

The following example creates an AWS Cloud Map namespace that
supports API calls, creates a service in that namespace, and
registers an instance to it:

```ts
import * as cdk from '../../core';
import * as servicediscovery from '../lib';

const app = new cdk.App();
const stack = new cdk.Stack(app, 'aws-servicediscovery-integ');

const namespace = new servicediscovery.HttpNamespace(stack, 'MyNamespace', {
  name: 'MyHTTPNamespace',
});

const service1 = namespace.createService('NonIpService', {
  description: 'service registering non-ip instances',
});

service1.registerNonIpInstance('NonIpInstance', {
  customAttributes: { arn: 'arn:aws:s3:::amzn-s3-demo-bucket' },
});

const service2 = namespace.createService('IpService', {
  description: 'service registering ip instances',
  healthCheck: {
    type: servicediscovery.HealthCheckType.HTTP,
    resourcePath: '/check',
  },
});

service2.registerIpInstance('IpInstance', {
  ipv4: '54.239.25.192',
});

app.synth();
```

## Private DNS Namespace Example

The following example creates an AWS Cloud Map namespace that
supports both API calls and DNS queries within a vpc, creates a
service in that namespace, and registers a loadbalancer as an
instance.

A secondary service is also configured which only supports API based discovery, a
non ip based resource is registered to this service:

```ts
import * as ec2 from '../../aws-ec2';
import * as elbv2 from '../../aws-elasticloadbalancingv2';
import * as cdk from '../../core';
import * as servicediscovery from '../lib';

const app = new cdk.App();
const stack = new cdk.Stack(app, 'aws-servicediscovery-integ');

const vpc = new ec2.Vpc(stack, 'Vpc', { maxAzs: 2 });

const namespace = new servicediscovery.PrivateDnsNamespace(stack, 'Namespace', {
  name: 'boobar.com',
  vpc,
});

const service = namespace.createService('Service', {
  dnsRecordType: servicediscovery.DnsRecordType.A_AAAA,
  dnsTtl: cdk.Duration.seconds(30),
  loadBalancer: true,
});

const loadbalancer = new elbv2.ApplicationLoadBalancer(stack, 'LB', { vpc, internetFacing: true });

service.registerLoadBalancer('Loadbalancer', loadbalancer);

const arnService = namespace.createService('ArnService', {
  discoveryType: servicediscovery.DiscoveryType.API,
});

arnService.registerNonIpInstance('NonIpInstance', {
  customAttributes: { arn: 'arn://' },
});

app.synth();
```

## Public DNS Namespace Example

The following example creates an AWS Cloud Map namespace that
supports both API calls and public DNS queries, creates a service in
that namespace, and registers an IP instance:

```ts
import * as cdk from '../../core';
import * as servicediscovery from '../lib';

const app = new cdk.App();
const stack = new cdk.Stack(app, 'aws-servicediscovery-integ');

const namespace = new servicediscovery.PublicDnsNamespace(stack, 'Namespace', {
  name: 'foobar.com',
});

const service = namespace.createService('Service', {
  name: 'foo',
  dnsRecordType: servicediscovery.DnsRecordType.A,
  dnsTtl: cdk.Duration.seconds(30),
  healthCheck: {
    type: servicediscovery.HealthCheckType.HTTPS,
    resourcePath: '/healthcheck',
    failureThreshold: 2,
  },
});

service.registerIpInstance('IpInstance', {
  ipv4: '54.239.25.192',
  port: 443,
});

app.synth();
```

For DNS namespaces, you can also register instances to services with CNAME records:

```ts
import * as cdk from '../../core';
import * as servicediscovery from '../lib';

const app = new cdk.App();
const stack = new cdk.Stack(app, 'aws-servicediscovery-integ');

const namespace = new servicediscovery.PublicDnsNamespace(stack, 'Namespace', {
  name: 'foobar.com',
});

const service = namespace.createService('Service', {
  name: 'foo',
  dnsRecordType: servicediscovery.DnsRecordType.CNAME,
  dnsTtl: cdk.Duration.seconds(30),
});

service.registerCnameInstance('CnameInstance', {
  instanceCname: 'service.pizza',
});

app.synth();
```

## Types

| Name | Kind | Summary |
| --- | --- | --- |
| [`AliasTargetInstance`](/v2/docs/aws-cdk-lib.aws_servicediscovery.AliasTargetInstance) | Construct (L2) | Instance that uses Route 53 Alias record type. |
| [`CnameInstance`](/v2/docs/aws-cdk-lib.aws_servicediscovery.CnameInstance) | Construct (L2) | Instance that is accessible using a domain name (CNAME). |
| [`HttpNamespace`](/v2/docs/aws-cdk-lib.aws_servicediscovery.HttpNamespace) | Construct (L2) | Define an HTTP Namespace. |
| [`InstanceBase`](/v2/docs/aws-cdk-lib.aws_servicediscovery.InstanceBase) | Construct (L2) |  |
| [`IpInstance`](/v2/docs/aws-cdk-lib.aws_servicediscovery.IpInstance) | Construct (L2) | Instance that is accessible using an IP address. |
| [`NonIpInstance`](/v2/docs/aws-cdk-lib.aws_servicediscovery.NonIpInstance) | Construct (L2) | Instance accessible using values other than an IP address or a domain name (CNAME). |
| [`PrivateDnsNamespace`](/v2/docs/aws-cdk-lib.aws_servicediscovery.PrivateDnsNamespace) | Construct (L2) | Define a Service Discovery HTTP Namespace. |
| [`PublicDnsNamespace`](/v2/docs/aws-cdk-lib.aws_servicediscovery.PublicDnsNamespace) | Construct (L2) | Define a Public DNS Namespace. |
| [`Service`](/v2/docs/aws-cdk-lib.aws_servicediscovery.Service) | Construct (L2) | Define a CloudMap Service. |
| [`CfnHttpNamespace`](/v2/docs/aws-cdk-lib.aws_servicediscovery.CfnHttpNamespace) | Construct (L1) | Creates an HTTP namespace. |
| [`CfnInstance`](/v2/docs/aws-cdk-lib.aws_servicediscovery.CfnInstance) | Construct (L1) | A complex type that contains information about an instance that AWS Cloud Map creates when you submit a `RegisterInstance` request. |
| [`CfnPrivateDnsNamespace`](/v2/docs/aws-cdk-lib.aws_servicediscovery.CfnPrivateDnsNamespace) | Construct (L1) | Creates a private namespace based on DNS, which is visible only inside a specified Amazon VPC. |
| [`CfnPublicDnsNamespace`](/v2/docs/aws-cdk-lib.aws_servicediscovery.CfnPublicDnsNamespace) | Construct (L1) | Creates a public namespace based on DNS, which is visible on the internet. |
| [`CfnService`](/v2/docs/aws-cdk-lib.aws_servicediscovery.CfnService) | Construct (L1) | A complex type that contains information about the specified service. |
| [`AliasTargetInstanceProps`](/v2/docs/aws-cdk-lib.aws_servicediscovery.AliasTargetInstanceProps) | Struct |  |
| [`BaseInstanceProps`](/v2/docs/aws-cdk-lib.aws_servicediscovery.BaseInstanceProps) | Struct | Used when the resource that's associated with the service instance is accessible using values other than an IP address or a domain name (CNAME), i.e. for non-ip-instances. |
| [`BaseNamespaceProps`](/v2/docs/aws-cdk-lib.aws_servicediscovery.BaseNamespaceProps) | Struct |  |
| [`BaseServiceProps`](/v2/docs/aws-cdk-lib.aws_servicediscovery.BaseServiceProps) | Struct | Basic props needed to create a service in a given namespace. |
| [`CfnHttpNamespaceProps`](/v2/docs/aws-cdk-lib.aws_servicediscovery.CfnHttpNamespaceProps) | Struct | Properties for defining a `CfnHttpNamespace`. |
| [`CfnInstanceProps`](/v2/docs/aws-cdk-lib.aws_servicediscovery.CfnInstanceProps) | Struct | Properties for defining a `CfnInstance`. |
| [`CfnPrivateDnsNamespace.PrivateDnsPropertiesMutableProperty`](/v2/docs/aws-cdk-lib.aws_servicediscovery.CfnPrivateDnsNamespace.PrivateDnsPropertiesMutableProperty) | Struct | DNS properties for the private DNS namespace. |
| [`CfnPrivateDnsNamespace.PropertiesProperty`](/v2/docs/aws-cdk-lib.aws_servicediscovery.CfnPrivateDnsNamespace.PropertiesProperty) | Struct | Properties for the private DNS namespace. |
| [`CfnPrivateDnsNamespace.SOAProperty`](/v2/docs/aws-cdk-lib.aws_servicediscovery.CfnPrivateDnsNamespace.SOAProperty) | Struct | Start of Authority (SOA) properties for a public or private DNS namespace. |
| [`CfnPrivateDnsNamespaceProps`](/v2/docs/aws-cdk-lib.aws_servicediscovery.CfnPrivateDnsNamespaceProps) | Struct | Properties for defining a `CfnPrivateDnsNamespace`. |
| [`CfnPublicDnsNamespace.PropertiesProperty`](/v2/docs/aws-cdk-lib.aws_servicediscovery.CfnPublicDnsNamespace.PropertiesProperty) | Struct | Properties for the public DNS namespace. |
| [`CfnPublicDnsNamespace.PublicDnsPropertiesMutableProperty`](/v2/docs/aws-cdk-lib.aws_servicediscovery.CfnPublicDnsNamespace.PublicDnsPropertiesMutableProperty) | Struct | DNS properties for the public DNS namespace. |
| [`CfnPublicDnsNamespace.SOAProperty`](/v2/docs/aws-cdk-lib.aws_servicediscovery.CfnPublicDnsNamespace.SOAProperty) | Struct | Start of Authority (SOA) properties for a public or private DNS namespace. |
| [`CfnPublicDnsNamespaceProps`](/v2/docs/aws-cdk-lib.aws_servicediscovery.CfnPublicDnsNamespaceProps) | Struct | Properties for defining a `CfnPublicDnsNamespace`. |
| [`CfnService.DnsConfigProperty`](/v2/docs/aws-cdk-lib.aws_servicediscovery.CfnService.DnsConfigProperty) | Struct | A complex type that contains information about the Amazon Route 53 DNS records that you want AWS Cloud Map to create when you register an instance. |
| [`CfnService.DnsRecordProperty`](/v2/docs/aws-cdk-lib.aws_servicediscovery.CfnService.DnsRecordProperty) | Struct | A complex type that contains information about the Route 53 DNS records that you want AWS Cloud Map to create when you register an instance. |
| [`CfnService.HealthCheckConfigProperty`](/v2/docs/aws-cdk-lib.aws_servicediscovery.CfnService.HealthCheckConfigProperty) | Struct | *Public DNS and HTTP namespaces only.* A complex type that contains settings for an optional health check. If you specify settings for a health check, AWS Cloud Map associates the health check with the records that you specify in `DnsConfig` . |
| [`CfnService.HealthCheckCustomConfigProperty`](/v2/docs/aws-cdk-lib.aws_servicediscovery.CfnService.HealthCheckCustomConfigProperty) | Struct | A complex type that contains information about an optional custom health check. |
| [`CfnServiceProps`](/v2/docs/aws-cdk-lib.aws_servicediscovery.CfnServiceProps) | Struct | Properties for defining a `CfnService`. |
| [`CnameInstanceBaseProps`](/v2/docs/aws-cdk-lib.aws_servicediscovery.CnameInstanceBaseProps) | Struct |  |
| [`CnameInstanceProps`](/v2/docs/aws-cdk-lib.aws_servicediscovery.CnameInstanceProps) | Struct |  |
| [`DiscoveryType`](/v2/docs/aws-cdk-lib.aws_servicediscovery.DiscoveryType) | Enum | Specifies information about the discovery type of a service. |
| [`DnsRecordType`](/v2/docs/aws-cdk-lib.aws_servicediscovery.DnsRecordType) | Enum |  |
| [`DnsServiceProps`](/v2/docs/aws-cdk-lib.aws_servicediscovery.DnsServiceProps) | Struct | Service props needed to create a service in a given namespace. |
| [`HealthCheckConfig`](/v2/docs/aws-cdk-lib.aws_servicediscovery.HealthCheckConfig) | Struct | Settings for an optional Amazon Route 53 health check. |
| [`HealthCheckCustomConfig`](/v2/docs/aws-cdk-lib.aws_servicediscovery.HealthCheckCustomConfig) | Struct | Specifies information about an optional custom health check. |
| [`HealthCheckType`](/v2/docs/aws-cdk-lib.aws_servicediscovery.HealthCheckType) | Enum |  |
| [`HttpNamespaceAttributes`](/v2/docs/aws-cdk-lib.aws_servicediscovery.HttpNamespaceAttributes) | Struct |  |
| [`HttpNamespaceProps`](/v2/docs/aws-cdk-lib.aws_servicediscovery.HttpNamespaceProps) | Struct |  |
| [`IHttpNamespace`](/v2/docs/aws-cdk-lib.aws_servicediscovery.IHttpNamespace) | Interface |  |
| [`IInstance`](/v2/docs/aws-cdk-lib.aws_servicediscovery.IInstance) | Interface |  |
| [`INamespace`](/v2/docs/aws-cdk-lib.aws_servicediscovery.INamespace) | Interface | A type of namespace. |
| [`IpInstanceBaseProps`](/v2/docs/aws-cdk-lib.aws_servicediscovery.IpInstanceBaseProps) | Struct |  |
| [`IpInstanceProps`](/v2/docs/aws-cdk-lib.aws_servicediscovery.IpInstanceProps) | Struct |  |
| [`IPrivateDnsNamespace`](/v2/docs/aws-cdk-lib.aws_servicediscovery.IPrivateDnsNamespace) | Interface |  |
| [`IPublicDnsNamespace`](/v2/docs/aws-cdk-lib.aws_servicediscovery.IPublicDnsNamespace) | Interface |  |
| [`IService`](/v2/docs/aws-cdk-lib.aws_servicediscovery.IService) | Interface |  |
| [`NamespaceType`](/v2/docs/aws-cdk-lib.aws_servicediscovery.NamespaceType) | Enum |  |
| [`NonIpInstanceBaseProps`](/v2/docs/aws-cdk-lib.aws_servicediscovery.NonIpInstanceBaseProps) | Struct |  |
| [`NonIpInstanceProps`](/v2/docs/aws-cdk-lib.aws_servicediscovery.NonIpInstanceProps) | Struct |  |
| [`PrivateDnsNamespaceAttributes`](/v2/docs/aws-cdk-lib.aws_servicediscovery.PrivateDnsNamespaceAttributes) | Struct |  |
| [`PrivateDnsNamespaceProps`](/v2/docs/aws-cdk-lib.aws_servicediscovery.PrivateDnsNamespaceProps) | Struct |  |
| [`PublicDnsNamespaceAttributes`](/v2/docs/aws-cdk-lib.aws_servicediscovery.PublicDnsNamespaceAttributes) | Struct |  |
| [`PublicDnsNamespaceProps`](/v2/docs/aws-cdk-lib.aws_servicediscovery.PublicDnsNamespaceProps) | Struct |  |
| [`RoutingPolicy`](/v2/docs/aws-cdk-lib.aws_servicediscovery.RoutingPolicy) | Enum |  |
| [`ServiceAttributes`](/v2/docs/aws-cdk-lib.aws_servicediscovery.ServiceAttributes) | Struct |  |
| [`ServiceProps`](/v2/docs/aws-cdk-lib.aws_servicediscovery.ServiceProps) | Struct |  |
