|
1 | | -#bin/sh |
| 1 | +#!/bin/sh |
2 | 2 |
|
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} |
12 | 5 |
|
13 | 6 | SVC_URL="" |
14 | 7 |
|
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 |
19 | 24 | 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) |
25 | 28 | elif [ "$COMPUTE" = "local" ]; then |
26 | 29 | SVC_URL="http://localhost:8080" |
27 | 30 | fi |
28 | 31 |
|
29 | 32 | # Check if URL was successfully set |
30 | | -if [ -z "$SVC_URL" ]; then |
| 33 | +if [ -z "$SVC_URL" ] || [ "$SVC_URL" = "http://" ]; then |
31 | 34 | echo "Error: Failed to retrieve service URL for compute target '$COMPUTE'" |
32 | 35 | exit 1 |
33 | 36 | fi |
|
0 commit comments