Skip to content

Commit b8e0bf0

Browse files
committed
Fix in backend stack
1 parent 425441f commit b8e0bf0

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

backend/src/iac/backend-stack.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,29 +114,31 @@ export class BackendStack extends cdk.Stack {
114114
);
115115

116116
// 3. HTTP 80 Listener
117-
alb.addListener(`${appName}HttpListener-${props.environment}`, {
117+
const httpListener = alb.addListener(`${appName}HttpListener-${props.environment}`, {
118118
port: 80,
119119
protocol: elbv2.ApplicationProtocol.HTTP,
120-
defaultAction: elbv2.ListenerAction.redirect({
121-
protocol: elbv2.ApplicationProtocol.HTTPS,
122-
}),
120+
defaultAction: elbv2.ListenerAction.forward([targetGroup]),
123121
});
124122

125-
// 4. Create Fargate Service
123+
// 4. Create a security group for the Fargate service
124+
const serviceSecurityGroup = new ec2.SecurityGroup(this, `${appName}ServiceSG-${props.environment}`, {
125+
vpc,
126+
allowAllOutbound: true,
127+
});
128+
129+
// 5. Create the Fargate service WITHOUT registering it with the target group yet
126130
const fargateService = new ecs.FargateService(this, `${appName}Service-${props.environment}`, {
127131
cluster,
128132
taskDefinition,
129133
desiredCount: isProd ? 2 : 1,
130134
assignPublicIp: false,
131-
securityGroups: [
132-
new ec2.SecurityGroup(this, `${appName}ServiceSG-${props.environment}`, {
133-
vpc,
134-
allowAllOutbound: true,
135-
}),
136-
],
135+
securityGroups: [serviceSecurityGroup],
137136
});
138137

139-
// 5. Register the service with the Target Group
138+
// 6. Add explicit dependency to ensure the listener exists before the service
139+
fargateService.node.addDependency(httpListener);
140+
141+
// 7. Now register the service with the target group
140142
targetGroup.addTarget(fargateService);
141143

142144
// Create a Cognito User Pool Client for the ALB

0 commit comments

Comments
 (0)