Skip to main content

The CDK Construct Library for AWS::ServiceDiscovery

Project description

Amazon ECS Service Discovery Construct Library


Stability: Stable


This module is part of the AWS Cloud Development Kit 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

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:

import cdk = require('@aws-cdk/core');
import servicediscovery = require('../lib');

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

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

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

service1.registerNonIpInstance('NonIpInstance', {
  customAttributes: { arn: 'arn:aws:s3:::mybucket' }
});

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:

import ec2 = require('@aws-cdk/aws-ec2');
import elbv2 = require('@aws-cdk/aws-elasticloadbalancingv2');
import cdk = require('@aws-cdk/core');
import servicediscovery = require('../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);

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:

import cdk = require('@aws-cdk/core');
import servicediscovery = require('../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:

import cdk = require('@aws-cdk/core');
import servicediscovery = require('../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();

Project details


Release history Release notifications | RSS feed

This version

1.3.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aws-cdk.aws-servicediscovery-1.3.0.tar.gz (95.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aws_cdk.aws_servicediscovery-1.3.0-py3-none-any.whl (93.9 kB view details)

Uploaded Python 3

File details

Details for the file aws-cdk.aws-servicediscovery-1.3.0.tar.gz.

File metadata

  • Download URL: aws-cdk.aws-servicediscovery-1.3.0.tar.gz
  • Upload date:
  • Size: 95.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.5

File hashes

Hashes for aws-cdk.aws-servicediscovery-1.3.0.tar.gz
Algorithm Hash digest
SHA256 068ac58dd665f916c0adf30eeef8f13fcce08c104142f3c1430ce5441b3a554c
MD5 bf2818400360ba5199da3e0616d0a97b
BLAKE2b-256 6c8ad87d35e3fe40e8a1e876103d9f740347e8aa6686f36a8b9645ec5c767885

See more details on using hashes here.

File details

Details for the file aws_cdk.aws_servicediscovery-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: aws_cdk.aws_servicediscovery-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 93.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.5

File hashes

Hashes for aws_cdk.aws_servicediscovery-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cc8266f5b2b2741847a7c801c1b2da748b88735c4cfff0688f50e635e46de9af
MD5 eac178f4ed1cdadcb09306063afe1d24
BLAKE2b-256 2c0c9db99c00df26d97cc733fcb4ea72954f477de8b6d00b7b4e6790d8c2dcb2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page