-
Notifications
You must be signed in to change notification settings - Fork 0
/
serviceconnect.ts
61 lines (51 loc) · 1.68 KB
/
serviceconnect.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
57
58
59
60
61
import { IConnectable } from "aws-cdk-lib/aws-ec2";
import { App, Stack } from "aws-cdk-lib";
import { ServiceConnectCluster } from "./serviceconnect/cluster";
import { ServiceConnectExpress } from "./serviceconnect/express";
interface Props {
namespaceName: string;
externalAccess: IConnectable;
}
export class ServiceConnectApp extends App {
constructor(props: Props) {
super();
const { namespaceName, externalAccess } = props;
// create ourselves an empty stack to hold our resources
const stack = new Stack(this, namespaceName);
/**
* create our ECS Cluster that is configured to use ECS Service Connect
*
* `cluster` our ECS Cluster with underlying default VPC
* `namespace` our Cloud Map namespace created by ECS Service Connect
* `securityGroup` security group accessible from our IP to make things easy
**/
const { cluster, namespace, securityGroup } = new ServiceConnectCluster(
stack,
"Cluster",
{
namespaceName,
externalAccess,
}
);
/**
* create two ECS Services, "blue" and "green", running our sample Express.js
* application that are configured to use ECS Service Connect
*
* we can use the /downstream endpoint of our sample application to explore
* how these services are able to discover and route traffic to each other
* as they have been connected to the same namespace
**/
new ServiceConnectExpress(stack, "Blue", {
serviceName: "blue",
cluster,
namespace,
securityGroup,
});
new ServiceConnectExpress(stack, "Green", {
serviceName: "green",
cluster,
namespace,
securityGroup,
});
}
}