colossal-tent-75408
01/14/2020, 5:36 PMimport * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";
// CORE CONFIGURATION
const cluster = new awsx.ecs.Cluster("stack-cluster");
const lb = new awsx.lb.ApplicationLoadBalancer("loadbalancer", { external: true });
const web = lb.createListener("web", { protocol: "HTTP", defaultAction: {
type: "fixed-response",
fixedResponse: {
statusCode: "503",
contentType: "application/json"
}
} })
const defaultCertificateArn = "";
const webHttps = lb.createListener("web-https", { protocol: "HTTPS", certificateArn: defaultCertificateArn, defaultAction: {
type: "fixed-response",
fixedResponse: {
statusCode: "503",
contentType: "application/json"
}
} })
const repo = new awsx.ecr.Repository("my-repo");
// FIRST SERVICE (GitHub repo 2)
const targetgroup1 = lb.createTargetGroup("targetgroup1", { protocol: "HTTP", port: 80 });
const app1Certificate = new aws.alb.ListenerCertificate("app1", {
certificateArn: "",
listenerArn: webHttps.listener.arn,
});
const rule1 = new awsx.lb.ListenerRule("http-app1", web, { conditions: [{ field: "host-header", values: "<http://app1.domain.com|app1.domain.com>" }], actions: [{type: "forward", targetGroupArn: targetgroup1.targetGroup.arn }]})
const ruleHttps1 = new awsx.lb.ListenerRule("https-app1", webHttps, { conditions: [{ field: "host-header", values: "<http://app1.domain.com|app1.domain.com>" }], actions: [{type: "forward", targetGroupArn: targetgroup1.targetGroup.arn }]})
const app1 = repo.buildAndPushImage("./app1");
const app1Service = new awsx.ecs.FargateService("app1", {
cluster,
taskDefinitionArgs: {
containers: {
app1: {
image: app1,
portMappings: [targetgroup1],
},
},
},
desiredCount: 2,
});
// SECOND SERVICE (GitHub repo 3)
const targetgroup2 = lb.createTargetGroup("targetgroup2", { protocol: "HTTP", port: 80 });
const app2Certificate = new aws.alb.ListenerCertificate("app2", {
certificateArn: "",
listenerArn: webHttps.listener.arn,
});
const rule2 = new awsx.lb.ListenerRule("http-app2", web, { conditions: [{ field: "host-header", values: "<http://app2.domain.com|app2.domain.com>" }], actions: [{type: "forward", targetGroupArn: targetgroup2.targetGroup.arn }]})
const ruleHttps2 = new awsx.lb.ListenerRule("https-app2", webHttps, { conditions: [{ field: "host-header", values: "<http://app2.domain.com|app2.domain.com>" }], actions: [{type: "forward", targetGroupArn: targetgroup2.targetGroup.arn }]})
const app2 = repo.buildAndPushImage("./app2");
let app2Service = new awsx.ecs.FargateService("app2", {
cluster,
desiredCount: 2,
taskDefinitionArgs: {
containers: {
app2: {
image: app2,
portMappings: [ targetgroup2 ],
},
},
},
});
handsome-truck-95168
01/14/2020, 10:54 PMcolossal-tent-75408
01/15/2020, 6:41 AMhandsome-truck-95168
01/15/2020, 9:22 PM