thankful-coat-47937
03/09/2022, 11:05 PMimport * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";
// Create an ECS cluster explicitly, and give it a name tag.
const vpc = awsx.ec2.Vpc.getDefault();
const cluster = new awsx.ecs.Cluster("cluster", {
vpc,
});
const zone = aws.route53.getZone({ name: "zone." });
// Create a load balancer on port 80 and spin up two instances of Nginx.
const lb = new awsx.lb.ApplicationLoadBalancer("alb");
const httpListener = lb.createListener("http", {
port: 80,
protocol: "HTTP",
defaultAction: {
type: "redirect",
redirect: { protocol: "HTTPS", port: "443", statusCode: "HTTP_301" },
},
});
const httpsListener = lb.createListener("https", {
port: 443,
protocol: "HTTPS",
certificateArn,
});
const record = new aws.route53.Record("api-route", {
zoneId: zone.then((zone) => zone.id),
name,
type: "A",
aliases: [
{
name: lb.loadBalancer.dnsName,
zoneId: lb.loadBalancer.zoneId,
evaluateTargetHealth: false,
},
],
});
const app = new awsx.ecs.FargateService("service", {
cluster,
taskDefinitionArgs: {
containers: {
nginx: {
image: "nginx",
portMappings: [httpsListener]
},
},
},
desiredCount: 2,
});
this makes all the requests go to the target group on port 443, but the target group is a service listening on port 80, so it 502sclever-sunset-76585
03/11/2022, 1:27 AMconst targetGroup = lb.createTargetGroup("...", {..., port: <your container port>});
const httpsListener = targetGroup.createListener("...", {protocol: "HTTPS"});