Skip to content

Commit 2041cc6

Browse files
author
Yuriy Bezsonov
committed
fix(infra): improve service URL retrieval script with better error handling
1 parent 457d69c commit 2041cc6

1 file changed

Lines changed: 23 additions & 20 deletions

File tree

infra/scripts/test/getsvcurl.sh

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
1-
#bin/sh
1+
#!/bin/sh
22

3-
# Check if parameter is provided
4-
if [ -z "$1" ]; then
5-
echo "Error: Compute target parameter is required"
6-
echo "Usage: $0 <compute-target>"
7-
echo "Valid compute targets: apprunner, ecs, eks, lambda, local"
8-
exit 1
9-
fi
10-
11-
COMPUTE=$1
3+
# Default to EKS if no parameter provided
4+
COMPUTE=${1:-eks}
125

136
SVC_URL=""
147

15-
if [ "$COMPUTE" = "apprunner" ]; then
16-
SVC_URL=https://$(aws apprunner list-services --query "ServiceSummaryList[?ServiceName == 'unicorn-store-spring'].ServiceUrl" --output text)
17-
elif [ "$COMPUTE" = "ecs" ]; then
18-
SVC_URL=http://$(aws elbv2 describe-load-balancers --names unicorn-store-spring --query "LoadBalancers[0].DNSName" --output text)
8+
if [ "$COMPUTE" = "ecs" ]; then
9+
# Try Express Mode first (HTTPS)
10+
EXPRESS_URL=$(aws ecs describe-express-gateway-service \
11+
--service-arn arn:aws:ecs:${AWS_REGION}:${ACCOUNT_ID}:service/unicorn-store-spring/unicorn-store-spring \
12+
--no-cli-pager 2>/dev/null \
13+
| jq -r '.service.activeConfigurations[0].ingressPaths[0].endpoint // empty')
14+
if [ -n "$EXPRESS_URL" ]; then
15+
SVC_URL=https://${EXPRESS_URL}
16+
else
17+
# Fall back to regular ECS with ALB (HTTP)
18+
ALB_DNS=$(aws elbv2 describe-load-balancers --names unicorn-store-spring \
19+
--query "LoadBalancers[0].DNSName" --output text --no-cli-pager 2>/dev/null)
20+
if [ -n "$ALB_DNS" ] && [ "$ALB_DNS" != "None" ]; then
21+
SVC_URL=http://${ALB_DNS}
22+
fi
23+
fi
1924
elif [ "$COMPUTE" = "eks" ]; then
20-
SVC_URL=http://$(kubectl get ingress unicorn-store-spring -n unicorn-store-spring -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
21-
elif [ "$COMPUTE" = "lambda" ]; then
22-
REST_API_ID=$(aws apigateway get-rest-apis --query 'items[?name==`unicorn-store-spring-api`].[id]' --output text)
23-
STAGE=$(aws apigateway get-stages --rest-api-id $REST_API_ID --query 'item[].stageName' --output text)
24-
SVC_URL=https://$REST_API_ID.execute-api.$AWS_REGION.amazonaws.com/$STAGE
25+
SVC_URL=http://$(kubectl get ingress unicorn-store-spring \
26+
-n unicorn-store-spring \
27+
-o jsonpath='{.status.loadBalancer.ingress[0].hostname}' 2>/dev/null)
2528
elif [ "$COMPUTE" = "local" ]; then
2629
SVC_URL="http://localhost:8080"
2730
fi
2831

2932
# Check if URL was successfully set
30-
if [ -z "$SVC_URL" ]; then
33+
if [ -z "$SVC_URL" ] || [ "$SVC_URL" = "http://" ]; then
3134
echo "Error: Failed to retrieve service URL for compute target '$COMPUTE'"
3235
exit 1
3336
fi

0 commit comments

Comments
 (0)