@@ -80,7 +80,7 @@ SUBNET_PUBLIC_2=$(aws ec2 describe-subnets \
8080 --filters " Name=vpc-id,Values=$VPC_ID " " Name=tag:Name,Values=*PublicSubnet2" \
8181 --query ' Subnets[0].SubnetId' --output text) && echo $SUBNET_PUBLIC_2
8282SECURITY_GROUP_ALB_ID=$( aws ec2 describe-security-groups --filters " Name=vpc-id,Values='$VPC_ID '" \
83- --query ' SecurityGroups[?GroupName==`' unicorn-store-spring-ecs-sg-alb' `].GroupId' --output text) echo $SECURITY_GROUP_ALB_ID
83+ --query ' SecurityGroups[?GroupName==`' unicorn-store-spring-ecs-sg-alb' `].GroupId' --output text) && echo $SECURITY_GROUP_ALB_ID
8484
8585aws elbv2 create-load-balancer --no-cli-pager \
8686 --name unicorn-store-spring \
@@ -97,6 +97,19 @@ aws elbv2 create-target-group --no-cli-pager \
9797 --vpc-id $VPC_ID \
9898 --target-type ip
9999
100+ TARGET_GROUP_ARN=$( aws elbv2 describe-target-groups --name unicorn-store-spring \
101+ --query ' TargetGroups[0].TargetGroupArn' --output text)
102+
103+ aws elbv2 modify-target-group \
104+ --target-group-arn $TARGET_GROUP_ARN \
105+ --health-check-path " /actuator/health" \
106+ --health-check-port " traffic-port" \
107+ --health-check-protocol HTTP \
108+ --health-check-interval-seconds 30 \
109+ --health-check-timeout-seconds 5 \
110+ --healthy-threshold-count 2 \
111+ --unhealthy-threshold-count 3
112+
100113ALB_ARN=$( aws elbv2 describe-load-balancers --name unicorn-store-spring \
101114 --query ' LoadBalancers[0].LoadBalancerArn' --output text) && echo $ALB_ARN
102115TARGET_GROUP_ARN=$( aws elbv2 describe-target-groups --name unicorn-store-spring \
@@ -111,6 +124,16 @@ aws elbv2 create-listener --no-cli-pager \
111124VPC_ID=$( aws ec2 describe-vpcs --filters " Name=tag:Name,Values=unicornstore-vpc" \
112125 --query ' Vpcs[0].VpcId' --output text) && echo $VPC_ID
113126
127+ EKS_VPC_CIDR=$( aws ec2 describe-vpcs \
128+ --vpc-ids " $VPC_ID " \
129+ --query " Vpcs[0].CidrBlock" --output text)
130+
131+ LAMBDA_SG_ID=$( aws cloudformation describe-stacks --stack-name unicornstore-stack --query " Stacks[0].Outputs[?ExportName=='LambdaSecurityGroupId'].OutputValue" --output text)
132+
133+ ECS_SG_ID=$( aws ec2 describe-security-groups --filters " Name=group-name,Values=unicorn-store-spring-ecs-sg" --query " SecurityGroups[0].GroupId" --output text)
134+
135+ sleep 1
136+
114137aws ec2 create-security-group \
115138 --group-name unicorn-store-spring-ecs-sg \
116139 --description " Security group for unicorn-store-spring ECS Service" \
@@ -122,6 +145,21 @@ aws ec2 authorize-security-group-ingress \
122145 --protocol tcp \
123146 --port 8080 \
124147 --source-group $SECURITY_GROUP_ALB_ID
148+ aws ec2 authorize-security-group-ingress \
149+ --group-id " $SECURITY_GROUP_ECS_ID " \
150+ --protocol tcp \
151+ --port 9090 \
152+ --cidr " $EKS_VPC_CIDR "
153+ aws ec2 authorize-security-group-ingress \
154+ --group-id " $SECURITY_GROUP_ECS_ID " \
155+ --protocol tcp \
156+ --port 9404 \
157+ --cidr " $EKS_VPC_CIDR "
158+ aws ec2 authorize-security-group-ingress \
159+ --group-id $ECS_SG_ID \
160+ --protocol tcp \
161+ --port 8080 \
162+ --source-group $LAMBDA_SG_ID
125163
126164TASK_DEFINITION_ARN=$( aws ecs describe-task-definition --task-definition unicorn-store-spring \
127165 --query ' taskDefinition.taskDefinitionArn' --output text) && echo $TASK_DEFINITION_ARN
@@ -140,6 +178,7 @@ aws ecs create-service --no-cli-pager \
140178 --cluster unicorn-store-spring \
141179 --service-name unicorn-store-spring \
142180 --task-definition $TASK_DEFINITION_ARN \
181+ --enable-execute-command \
143182 --desired-count 1 \
144183 --launch-type FARGATE \
145184 --network-configuration " awsvpcConfiguration={subnets=[$SUBNET_PRIVATE_1 ,$SUBNET_PRIVATE_2 ],securityGroups=[$SECURITY_GROUP_ECS_ID ],assignPublicIp=" DISABLED" }" \
0 commit comments