Skip to content
v2.278.0

DnsServiceProps Struct ​

Service props needed to create a service in a given namespace.

Used by createService() for PrivateDnsNamespace and PublicDnsNamespace

Example ​

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();
python
import aws_cdk as cdk
import aws_cdk as servicediscovery

app = cdk.App()
stack = cdk.Stack(app, "aws-servicediscovery-integ")

namespace = servicediscovery.PublicDnsNamespace(stack, "Namespace",
    name="foobar.com"
)

service = namespace.create_service("Service",
    name="foo",
    dns_record_type=servicediscovery.DnsRecordType.A,
    dns_ttl=cdk.Duration.seconds(30),
    health_check=cdk.aws_servicediscovery.HealthCheckConfig(
        type=servicediscovery.HealthCheckType.HTTPS,
        resource_path="/healthcheck",
        failure_threshold=2
    )
)

service.register_ip_instance("IpInstance",
    ipv4="54.239.25.192",
    port=443
)

app.synth()
java
import software.amazon.awscdk.*;
import software.amazon.awscdk.*;

App app = new App();
Stack stack = new Stack(app, "aws-servicediscovery-integ");

PublicDnsNamespace namespace = PublicDnsNamespace.Builder.create(stack, "Namespace")
        .name("foobar.com")
        .build();

Service service = namespace.createService("Service", DnsServiceProps.builder()
        .name("foo")
        .dnsRecordType(DnsRecordType.A)
        .dnsTtl(Duration.seconds(30))
        .healthCheck(HealthCheckConfig.builder()
                .type(HealthCheckType.HTTPS)
                .resourcePath("/healthcheck")
                .failureThreshold(2)
                .build())
        .build());

service.registerIpInstance("IpInstance", IpInstanceBaseProps.builder()
        .ipv4("54.239.25.192")
        .port(443)
        .build());

app.synth();
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK;
using Amazon.CDK;

var app = new App();
var stack = new Stack(app, "aws-servicediscovery-integ");

var namespace = new PublicDnsNamespace(stack, "Namespace", new PublicDnsNamespaceProps {
    Name = "foobar.com"
});

var service = namespace.CreateService("Service", new DnsServiceProps {
    Name = "foo",
    DnsRecordType = DnsRecordType.A,
    DnsTtl = Duration.Seconds(30),
    HealthCheck = new HealthCheckConfig {
        Type = HealthCheckType.HTTPS,
        ResourcePath = "/healthcheck",
        FailureThreshold = 2
    }
});

service.RegisterIpInstance("IpInstance", new IpInstanceBaseProps {
    Ipv4 = "54.239.25.192",
    Port = 443
});

app.Synth();
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

app := cdk.NewApp()
stack := cdk.NewStack(app, jsii.String("aws-servicediscovery-integ"))

namespace := servicediscovery.NewPublicDnsNamespace(stack, jsii.String("Namespace"), &PublicDnsNamespaceProps{
	Name: jsii.String("foobar.com"),
})

service := namespace.CreateService(jsii.String("Service"), &DnsServiceProps{
	Name: jsii.String("foo"),
	DnsRecordType: servicediscovery.DnsRecordType_A,
	DnsTtl: cdk.Duration_Seconds(jsii.Number(30)),
	HealthCheck: &HealthCheckConfig{
		Type: servicediscovery.HealthCheckType_HTTPS,
		ResourcePath: jsii.String("/healthcheck"),
		FailureThreshold: jsii.Number(2),
	},
})

service.RegisterIpInstance(jsii.String("IpInstance"), &IpInstanceBaseProps{
	Ipv4: jsii.String("54.239.25.192"),
	Port: jsii.Number(443),
})

app.Synth()

Properties ​

customHealthCheckoptionalHealthCheckCustomConfigcustom_health_checkoptionalHealthCheckCustomConfigcustomHealthCheckoptionalHealthCheckCustomConfigCustomHealthCheckoptionalHealthCheckCustomConfigCustomHealthCheckoptionalHealthCheckCustomConfig = none #
Structure containing failure threshold for a custom health checker.

Only one of healthCheckConfig or healthCheckCustomConfig can be specified. See: https://docs.aws.amazon.com/cloud-map/latest/api/API_HealthCheckCustomConfig.html

descriptionoptionalstringdescriptionoptionalstrdescriptionoptionalStringDescriptionoptionalstringDescriptionoptional*string = none #
A description of the service.
discoveryTypeoptionalDiscoveryTypediscovery_typeoptionalDiscoveryTypediscoveryTypeoptionalDiscoveryTypeDiscoveryTypeoptionalDiscoveryTypeDiscoveryTypeoptionalDiscoveryType = DNS_AND_API #
Controls how instances within this service can be discovered.
dnsRecordTypeoptionalDnsRecordTypedns_record_typeoptionalDnsRecordTypednsRecordTypeoptionalDnsRecordTypeDnsRecordTypeoptionalDnsRecordTypeDnsRecordTypeoptionalDnsRecordType = A #
The DNS type of the record that you want AWS Cloud Map to create.

Supported record types include A, AAAA, A and AAAA (A_AAAA), CNAME, and SRV.

dnsTtloptionalDurationdns_ttloptionalDurationdnsTtloptionalDurationDnsTtloptionalDurationDnsTtloptionalDuration = Duration.minutes(1) #
The amount of time, in seconds, that you want DNS resolvers to cache the settings for this record.
healthCheckoptionalHealthCheckConfighealth_checkoptionalHealthCheckConfighealthCheckoptionalHealthCheckConfigHealthCheckoptionalHealthCheckConfigHealthCheckoptionalHealthCheckConfig = none #
Settings for an optional health check.
notes

If you specify health check settings, AWS Cloud Map associates the health check with the records that you specify in DnsConfig. Only one of healthCheckConfig or healthCheckCustomConfig can be specified. Not valid for PrivateDnsNamespaces. If you use healthCheck, you can only register IP instances to this service.

loadBalanceroptionalbooleanload_balanceroptionalboolloadBalanceroptionalBooleanLoadBalanceroptionalboolLoadBalanceroptional*bool = false #
Whether or not this service will have an Elastic LoadBalancer registered to it as an AliasTargetInstance.

Setting this to true correctly configures the routingPolicy and performs some additional validation.

nameoptionalstringnameoptionalstrnameoptionalStringNameoptionalstringNameoptional*string #
A name for the Service.

Default: CloudFormation-generated name

routingPolicyoptionalRoutingPolicyrouting_policyoptionalRoutingPolicyroutingPolicyoptionalRoutingPolicyRoutingPolicyoptionalRoutingPolicyRoutingPolicyoptionalRoutingPolicy #
The routing policy that you want to apply to all DNS records that AWS Cloud Map creates when you register an instance and specify this service.

Default: WEIGHTED for CNAME records and when loadBalancer is true, MULTIVALUE otherwise