Skip to content

Commit 08006d1

Browse files
authored
minor: Unify and adjust API Gateway stage name (#27)
* minor: unify and adjust API GW stage name * minor fix in tests
1 parent 924e5e9 commit 08006d1

File tree

6 files changed

+19
-7
lines changed

6 files changed

+19
-7
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ usage: ## Show usage for this Makefile
55
deploy: ## Deploy the application to LocalStack
66
bin/deploy.sh
77

8+
deploy-cdk: ## Deploy the application to LocalStack via CDK
9+
AWS_CMD=awslocal CDK_CMD=cdklocal bin/deploy_cdk.sh
10+
811
web: ## Open the Web app in the browser (after the app is deployed)
912
DOMAIN_NAME=$$(awslocal cloudfront list-distributions | jq -r '.DistributionList.Items[0].DomainName'); \
1013
echo "CloudFront URL: https://$$DOMAIN_NAME"; \

bin/deploy.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ log "API endpoints set up successfully."
246246
log "Deploying API..."
247247
awslocal apigateway create-deployment \
248248
--rest-api-id $API_ID \
249-
--stage-name test >/dev/null
250-
API_ENDPOINT="http://localhost:4566/_aws/execute-api/$API_ID/test"
249+
--stage-name prod >/dev/null
250+
API_ENDPOINT="http://localhost:4566/_aws/execute-api/$API_ID/prod"
251251
log "API deployed. Endpoint: $API_ENDPOINT"
252252

253253
# SQS DLQ -> EventBridge Pipes -> SNS

bin/deploy_cdk.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ if [ ! -d frontend/build ]; then
1515
)
1616
fi
1717

18+
# bootstrap the stack
19+
(cd cdk
20+
npm run ${CDK_CMD} bootstrap
21+
)
22+
1823
# deploy bulk of the application
1924
(cd cdk
2025
npm run ${CDK_CMD} -- deploy --require-approval never QuizAppStack

bin/seed.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if [ -z "$API_ID" ]; then
2525
exit 1
2626
fi
2727

28-
API_ENDPOINT="$AWS_ENDPOINT_URL/_aws/execute-api/$API_ID/test"
28+
API_ENDPOINT="$AWS_ENDPOINT_URL/_aws/execute-api/$API_ID/prod"
2929

3030
create_quiz() {
3131
local quiz_data=$1

tests/test_infra.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
import json
66
import time
77

8+
API_NAME = 'QuizAPI'
9+
STAGE_NAME = "prod"
10+
11+
812
@pytest.fixture(scope='module')
913
def api_endpoint():
1014
apigateway_client = boto3.client('apigateway', endpoint_url='http://localhost:4566')
1115
lambda_client = boto3.client('lambda', endpoint_url='http://localhost:4566')
1216

13-
API_NAME = 'QuizAPI'
1417
response = apigateway_client.get_rest_apis()
1518
api_list = response.get('items', [])
1619
api = next((item for item in api_list if item['name'] == API_NAME), None)
@@ -19,7 +22,7 @@ def api_endpoint():
1922
raise Exception(f"API {API_NAME} not found.")
2023

2124
API_ID = api['id']
22-
API_ENDPOINT = f"http://localhost:4566/_aws/execute-api/{API_ID}/test"
25+
API_ENDPOINT = f"http://localhost:4566/_aws/execute-api/{API_ID}/{STAGE_NAME}"
2326

2427
print(f"API Endpoint: {API_ENDPOINT}")
2528

tests/test_outage.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from localstack.sdk.chaos.managers import fault_configuration
1010

1111
LOCALSTACK_ENDPOINT = "http://localhost.localstack.cloud:4566"
12-
API_NAME = 'QuizAPI'
12+
API_NAME = "QuizAPI"
13+
STAGE_NAME = "prod"
1314

1415
class TestLocalStackClient:
1516
client = localstack.sdk.chaos.ChaosClient()
@@ -28,7 +29,7 @@ def api_endpoint(apigateway_client):
2829
raise Exception(f"API {API_NAME} not found.")
2930

3031
API_ID = api['id']
31-
API_ENDPOINT = f"{LOCALSTACK_ENDPOINT}/_aws/execute-api/{API_ID}/test"
32+
API_ENDPOINT = f"{LOCALSTACK_ENDPOINT}/_aws/execute-api/{API_ID}/{STAGE_NAME}"
3233

3334
print(f"API Endpoint: {API_ENDPOINT}")
3435

0 commit comments

Comments
 (0)