Skip to content

Commit

Permalink
Try ALB AZ fix
Browse files Browse the repository at this point in the history
  • Loading branch information
alukach committed Jan 24, 2025
1 parent 7b7c764 commit d60ef2c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cdk/lib/KeycloakService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as ecrAssets from "aws-cdk-lib/aws-ecr-assets";
import * as secretsManager from "aws-cdk-lib/aws-secretsmanager";
import * as certificateManager from "aws-cdk-lib/aws-certificatemanager";
import * as ec2 from "aws-cdk-lib/aws-ec2";
import * as elbv2 from "aws-cdk-lib/aws-elasticloadbalancingv2";
import * as rds from "aws-cdk-lib/aws-rds";
import { StackProps } from "./KeycloakStack";
import { Construct } from "constructs";
Expand Down Expand Up @@ -55,12 +56,30 @@ export class KeycloakService extends Construct {
const appPort = 8080;
const healthManagementPort = 9000;

// Production has a public NAT Gateway subnet, which causes the
// default load balancer creation to fail with too many subnets
// being selected per AZ. We create our own load balancer to
// allow us to select subnets and avoid the issue.
const loadBalancer = new elbv2.ApplicationLoadBalancer(
this,
"load-balancer",
{
vpc: props.vpc,
internetFacing: true,
vpcSubnets: {
subnetType: ec2.SubnetType.PUBLIC,
onePerAz: true,
},
}
);

// Fargate Service with ALB, SSL, and Health Check
this.albService = new ecsPatterns.ApplicationLoadBalancedFargateService(
this,
"service",
{
vpc: props.vpc,
loadBalancer,
desiredCount: 1,
publicLoadBalancer: true,
listenerPort: 443,
Expand Down

0 comments on commit d60ef2c

Please sign in to comment.