-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,076 additions
and
327 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
packages/@aws-cdk/aws-servicediscovery/lib/alias-target-instance.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import cdk = require('@aws-cdk/cdk'); | ||
import { BaseInstanceProps, InstanceBase } from './instance'; | ||
import { NamespaceType } from './namespace'; | ||
import { DnsRecordType, IService, RoutingPolicy } from './service'; | ||
import { CfnInstance } from './servicediscovery.generated'; | ||
|
||
export interface AliasTargetInstanceProps extends BaseInstanceProps { | ||
/** | ||
* DNS name of the target | ||
*/ | ||
dnsName: string; | ||
|
||
/** | ||
* The Cloudmap service this resource is registered to. | ||
*/ | ||
service: IService; | ||
} | ||
|
||
export class AliasTargetInstance extends InstanceBase { | ||
/** | ||
* The Id of the instance | ||
*/ | ||
public readonly instanceId: string; | ||
|
||
/** | ||
* The Cloudmap service to which the instance is registered. | ||
*/ | ||
public readonly service: IService; | ||
|
||
/** | ||
* The Route53 DNS name of the alias target | ||
*/ | ||
public readonly dnsName: string; | ||
|
||
constructor(scope: cdk.Construct, id: string, props: AliasTargetInstanceProps) { | ||
super(scope, id); | ||
|
||
if (props.service.namespace.type === NamespaceType.Http) { | ||
throw new Error('Namespace associated with Service must be a DNS Namespace.'); | ||
} | ||
|
||
// Should already be enforced when creating service, but validates if service is not instantiated with #createService | ||
const dnsRecordType = props.service.dnsRecordType; | ||
if (dnsRecordType !== DnsRecordType.A | ||
&& dnsRecordType !== DnsRecordType.AAAA | ||
&& dnsRecordType !== DnsRecordType.A_AAAA) { | ||
throw new Error('Service must use `A` or `AAAA` records to register an AliasRecordTarget.'); | ||
} | ||
|
||
if (props.service.routingPolicy !== RoutingPolicy.Weighted) { | ||
throw new Error('Service must use `WEIGHTED` routing policy.'); | ||
} | ||
|
||
const resource = new CfnInstance(this, 'Resource', { | ||
instanceAttributes: { | ||
AWS_ALIAS_DNS_NAME: props.dnsName, | ||
...props.customAttributes | ||
}, | ||
instanceId: props.instanceId, | ||
serviceId: props.service.serviceId | ||
}); | ||
|
||
this.service = props.service; | ||
this.instanceId = resource.instanceId; | ||
this.dnsName = props.dnsName; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
packages/@aws-cdk/aws-servicediscovery/lib/cname-instance.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import cdk = require('@aws-cdk/cdk'); | ||
import { BaseInstanceProps, InstanceBase } from './instance'; | ||
import { NamespaceType } from './namespace'; | ||
import { DnsRecordType, IService } from './service'; | ||
import { CfnInstance } from './servicediscovery.generated'; | ||
|
||
export interface CnameInstanceBaseProps extends BaseInstanceProps { | ||
/** | ||
* If the service configuration includes a CNAME record, the domain name that you want Route 53 to return in | ||
* response to DNS queries, for example, example.com. This value is required if the service specified by ServiceId | ||
* includes settings for an CNAME record. | ||
*/ | ||
instanceCname: string; | ||
} | ||
|
||
export interface CnameInstanceProps extends CnameInstanceBaseProps { | ||
/** | ||
* The Cloudmap service this resource is registered to. | ||
*/ | ||
service: IService; | ||
} | ||
|
||
export class CnameInstance extends InstanceBase { | ||
/** | ||
* The Id of the instance | ||
*/ | ||
public readonly instanceId: string; | ||
|
||
/** | ||
* The Cloudmap service to which the instance is registered. | ||
*/ | ||
public readonly service: IService; | ||
|
||
/** | ||
* The domain name returned by DNS queries for the instance | ||
*/ | ||
public readonly instanceCname: string; | ||
|
||
constructor(scope: cdk.Construct, id: string, props: CnameInstanceProps) { | ||
super(scope, id); | ||
|
||
if (props.service.namespace.type === NamespaceType.Http) { | ||
throw new Error('Namespace associated with Service must be a DNS Namespace.'); | ||
} | ||
|
||
if (props.service.dnsRecordType === DnsRecordType.Cname) { | ||
if (!props.instanceCname) { | ||
throw new Error('A `instanceCname` must be specified for a service using a `CNAME` record.'); | ||
} | ||
} | ||
|
||
const resource = new CfnInstance(this, 'Resource', { | ||
instanceId: props.instanceId, | ||
serviceId: props.service.serviceId, | ||
instanceAttributes: { | ||
AWS_INSTANCE_CNAME: props.instanceCname, | ||
...props.customAttributes | ||
} | ||
}); | ||
|
||
this.service = props.service; | ||
this.instanceId = resource.instanceId; | ||
this.instanceCname = props.instanceCname; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.