forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
134 lines (112 loc) · 3.87 KB
/
index.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";
let config = new pulumi.Config("airflow");
const dbPassword = config.require("dbPassword");
let vpc = awsx.ec2.Vpc.getDefault();
// Create a basic cluster and autoscaling group
let cluster = new awsx.ecs.Cluster("airflow", { vpc });
let autoScalingGroup = cluster.createAutoScalingGroup("airflow", {
templateParameters: {
minSize: 20,
},
launchConfigurationArgs: {
instanceType: "t2.xlarge",
},
});
let securityGroupIds = cluster.securityGroups.map(g => g.id);
let dbSubnets = new aws.rds.SubnetGroup("dbsubnets", {
subnetIds: vpc.publicSubnetIds,
});
let db = new aws.rds.Instance("postgresdb", {
engine: "postgres",
instanceClass: "db.t2.micro",
allocatedStorage: 20,
dbSubnetGroupName: dbSubnets.id,
vpcSecurityGroupIds: securityGroupIds,
name: "airflow",
username: "airflow",
password: dbPassword,
skipFinalSnapshot: true,
});
let cacheSubnets = new aws.elasticache.SubnetGroup("cachesubnets", {
subnetIds: vpc.publicSubnetIds,
});
let cacheCluster = new aws.elasticache.Cluster("cachecluster", {
clusterId: "cache-" + pulumi.getStack(),
engine: "redis",
nodeType: "cache.t2.micro",
numCacheNodes: 1,
subnetGroupName: cacheSubnets.id,
securityGroupIds: securityGroupIds,
});
let hosts = pulumi.all([db.endpoint.apply(e => e.split(":")[0]), cacheCluster.cacheNodes[0].address]);
let environment = hosts.apply(([postgresHost, redisHost]) => [
{ name: "POSTGRES_HOST", value: postgresHost },
{ name: "POSTGRES_PASSWORD", value: dbPassword },
{ name: "REDIS_HOST", value: redisHost },
{ name: "EXECUTOR", value: "Celery" }
]);
let airflowControllerListener = new awsx.elasticloadbalancingv2.ApplicationListener("airflowcontroller", {
external: true,
port: 8080,
protocol: "HTTP",
});
let airflowController = new awsx.ecs.EC2Service("airflowcontroller", {
cluster,
desiredCount: 1,
taskDefinitionArgs: {
containers: {
"webserver": {
image: awsx.ecs.Image.fromPath("webserver", "./airflow-container"),
portMappings: [airflowControllerListener],
environment: environment,
command: [ "webserver" ],
memory: 128,
},
"scheduler": {
image: awsx.ecs.Image.fromPath("scheduler", "./airflow-container"),
environment: environment,
command: [ "scheduler" ],
memory: 128,
},
},
},
});
let airflowerListener = new awsx.elasticloadbalancingv2.ApplicationListener("airflower", {
port: 5555,
external: true,
protocol: "HTTP"
});
let airflower = new awsx.ecs.EC2Service("airflower", {
cluster,
taskDefinitionArgs: {
containers: {
// If the container is named "flower", we create environment variables that start
// with `FLOWER_` and Flower tries and fails to parse them as configuration.
"notflower": {
image: awsx.ecs.Image.fromPath("notflower", "./airflow-container"),
portMappings: [airflowerListener],
environment: environment,
command: [ "flower" ],
memory: 128,
},
},
},
});
let airflowWorkers = new awsx.ecs.EC2Service("airflowworkers", {
cluster,
desiredCount: 3,
taskDefinitionArgs: {
containers: {
"worker": {
image: awsx.ecs.Image.fromPath("worker", "./airflow-container"),
environment: environment,
command: [ "worker" ],
memory: 1024,
},
},
},
});
export let airflowEndpoint = airflowControllerListener.endpoint.hostname;
export let flowerEndpoint = airflowerListener.endpoint.hostname;