Skip to content

Commit dc64080

Browse files
committed
chore: add comments and docs to service connect structs
1 parent 2e41020 commit dc64080

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
@@ -580,6 +580,51 @@ new Service(this, 'Worker', {
580580
});
581581
```
582582
583+
## Aliased Port Extension
584+
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.
585+
586+
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.
587+
588+
```ts
589+
const environment = new Environment(this, 'production');
590+
591+
const serverDescription = new ServiceDescription() ;
592+
serverDescription.add(new Container({
593+
cpu: 256,
594+
memoryMiB: 512,
595+
trafficPort: 80,
596+
image: ecs.ContainerImage.fromRegistry('nathanpeck/name'),
597+
}));
598+
serverDescription.add(new AliasedPortExtension({
599+
alias: 'server',
600+
}));
601+
602+
new Service(this, 'Server', {
603+
environment,
604+
serviceDescription: serverDescription
605+
});
606+
607+
const clientDescription = new ServiceDescription();
608+
clientDescription.add(new Container({
609+
cpu: 256,
610+
memoryMiB: 512,
611+
trafficPort: 80,
612+
image: ecs.ContainerImage.fromRegistry('nathanpeck/greeter'),
613+
environment: {
614+
PORT: '80',
615+
NAME_URL: 'http://server'
616+
},
617+
}));
618+
619+
const clientService = new Service(this, 'client', {
620+
environment,
621+
serviceDescription: clientDescription,
622+
});
623+
clientService.enableServiceConnect();
624+
```
625+
626+
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`.
627+
583628
## Community Extensions
584629
585630
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
@@ -55,6 +55,13 @@ export interface ServiceProps {
5555
* @default none
5656
*/
5757
readonly autoScaleTaskCount?: AutoScalingOptions;
58+
59+
/**
60+
* Whether to opt this service in to Service Connect as a client.
61+
*
62+
* @default - true if an AliasedPortExtension was added to the service description, otherwise false
63+
*/
64+
readonly enableServiceConnect?: boolean;
5865
}
5966

6067
export interface AutoScalingOptions {

0 commit comments

Comments
 (0)