-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathinstance.ts
56 lines (49 loc) · 1.35 KB
/
instance.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { IResource, Resource } from '@aws-cdk/cdk';
import { IService } from './service';
export interface IInstance extends IResource {
/**
* The id of the instance resource
* @attribute
*/
readonly instanceId: string;
/**
* The Cloudmap service this resource is registered to.
*/
readonly service: IService;
}
/**
* 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
*/
export interface BaseInstanceProps {
/**
* The id of the instance resource
*
* @default Automatically generated name
*/
readonly instanceId?: string;
/**
* Custom attributes of the instance.
*
* @default none
*/
readonly customAttributes?: { [key: string]: string };
}
export abstract class InstanceBase extends Resource implements IInstance {
/**
* The Id of the instance
*/
public abstract readonly instanceId: string;
/**
* The Cloudmap service to which the instance is registered.
*/
public abstract readonly service: IService;
/**
* Generate a unique instance Id that is safe to pass to CloudMap
*/
protected uniqueInstanceId() {
// Max length of 64 chars, get the last 64 chars
const id = this.node.uniqueId;
return id.substring(Math.max(id.length - 64, 0), id.length);
}
}