Skip to content

Commit d5819c7

Browse files
committed
chore: add comments and docs to service connect structs
1 parent af412a5 commit d5819c7

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,51 @@ new Service(this, 'Worker', {
562562
});
563563
```
564564
565+
## Aliased Port Extension
566+
Amazon ECS Service Connect](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-connect.html#service-connect-concepts) is a simple-to-use managed service mesh offering. It involves the creation of a CloudMap Namespace in a service's environment, then the creation of one or more Service Connect Services which route traffic to any named port mapping on the service's task definition.
567+
568+
The following example adds an `AliasedPortExtension` to a Service, allowing other services which have opted in to Service Connect to reach it through its terse DNS alias.
569+
570+
```ts
571+
const environment = new Environment(this, 'production');
572+
573+
const serverDescription = new ServiceDescription() ;
574+
serverDescription.add(new Container({
575+
cpu: 256,
576+
memoryMiB: 512,
577+
trafficPort: 80,
578+
image: ecs.ContainerImage.fromRegistry('nathanpeck/name'),
579+
}));
580+
serverDescription.add(new AliasedPortExtension({
581+
alias: 'server',
582+
}));
583+
584+
new Service(this, 'Server', {
585+
environment,
586+
serviceDescription: serverDescription
587+
});
588+
589+
const clientDescription = new ServiceDescription();
590+
clientDescription.add(new Container({
591+
cpu: 256,
592+
memoryMiB: 512,
593+
trafficPort: 80,
594+
image: ecs.ContainerImage.fromRegistry('nathanpeck/greeter'),
595+
environment: {
596+
PORT: '80',
597+
NAME_URL: 'http://server'
598+
},
599+
}));
600+
601+
const clientService = new Service(this, 'client', {
602+
environment,
603+
serviceDescription: clientDescription,
604+
});
605+
clientService.enableServiceConnect();
606+
```
607+
608+
In the example above, the `server` service advertises its port `80` via a terse DNS alias `server`. The client opts in to ECS Service Connect and uses the short URL and port to access the server service. The `AliasedPortExtension` creates the necessary named port mapping on the Task Definition, adds a default CloudMap namespace to the environment, and registers the Service Connect Service under the container's `alias` and `trafficPort`.
609+
565610
## Community Extensions
566611
567612
We encourage the development of Community Service Extensions that support

src/extensions/aliased-port.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ContainerMutatingHook, ServiceBuild, ServiceExtension } from './extensi
66

77

88
/**
9-
* AliasedPortProps defines the properties of an aliased port extension
9+
* AliasedPortProps defines the properties of an aliased port extension.
1010
*/
1111
export interface AliasedPortProps {
1212
/**
@@ -30,6 +30,19 @@ export interface AliasedPortProps {
3030
readonly aliasPort?: number;
3131
}
3232

33+
/**
34+
* AliasedPortExtension allows services to opt in to Amazon ECS Service Connect using a terse DNS alias,
35+
* an optional protocol, and a port over which the service will receive Service Connect traffic.
36+
*
37+
* @example
38+
*
39+
* declare const description: ServiceDescription;
40+
* description.add(new AliasedPortExtension({
41+
* alias: 'backend-api',
42+
* appProtocol: ecs.AppProtocol.grpc,
43+
* aliasPort: 80,
44+
* }));
45+
*/
3346
export class AliasedPortExtension extends ServiceExtension {
3447
protected alias: string;
3548
protected aliasPort?: number;

src/service.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ export interface ServiceProps {
5454
* @default none
5555
*/
5656
readonly autoScaleTaskCount?: AutoScalingOptions;
57+
58+
/**
59+
* Whether to opt this service in to Service Connect as a client.
60+
*
61+
* @default - true if an AliasedPortExtension was added to the service description, otherwise false
62+
*/
63+
readonly enableServiceConnect?: boolean;
5764
}
5865

5966
export interface AutoScalingOptions {

0 commit comments

Comments
 (0)