Skip to content

Commit

Permalink
remove _user_request_ from endpoints for NextGen (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
bentsku authored Nov 25, 2024
1 parent 321ae0b commit 4ba0e2e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The output will be:

```bash
CloudFront URL: https://1e372b81.cloudfront.localhost.localstack.cloud
API Gateway Endpoint: http://localhost:4566/_aws/execute-api/4xu5emxibf/test/_user_request_
API Gateway Endpoint: http://localhost:4566/_aws/execute-api/4xu5emxibf/test
```

Navigate to the CloudFront URL to check out the app. The script would also seed some quiz data and user data to make local testing easier.
Expand Down
20 changes: 10 additions & 10 deletions bin/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,18 @@ FUNCTIONS=(
log "Creating IAM policies and roles for Lambda functions..."
for FUNCTION_INFO in "${FUNCTIONS[@]}"; do
read FUNCTION_NAME POLICY_FILE ROLE_NAME <<< "$FUNCTION_INFO"

log "Creating IAM policy for $FUNCTION_NAME..."
awslocal iam create-policy \
--policy-name ${FUNCTION_NAME}Policy \
--policy-document file://${POLICY_FILE} >/dev/null

log "Creating IAM role $ROLE_NAME..."
ROLE_ARN=$(awslocal iam create-role \
--role-name ${ROLE_NAME} \
--assume-role-policy-document file://configurations/lambda_trust_policy.json \
--query 'Role.Arn' --output text)

log "Attaching policy to role $ROLE_NAME..."
awslocal iam attach-role-policy \
--role-name ${ROLE_NAME} \
Expand Down Expand Up @@ -141,7 +141,7 @@ LAMBDAS=(

for LAMBDA_INFO in "${LAMBDAS[@]}"; do
read FUNCTION_NAME ZIP_FILE ROLE_NAME <<< "$LAMBDA_INFO"

log "Creating Lambda function $FUNCTION_NAME..."
awslocal lambda create-function \
--function-name ${FUNCTION_NAME} \
Expand Down Expand Up @@ -190,21 +190,21 @@ ENDPOINTS=(

for ENDPOINT_INFO in "${ENDPOINTS[@]}"; do
read PATH_PART HTTP_METHOD FUNCTION_NAME <<< "$ENDPOINT_INFO"

log "Setting up API endpoint /$PATH_PART [$HTTP_METHOD] -> $FUNCTION_NAME"

RESOURCE_ID=$(awslocal apigateway create-resource \
--rest-api-id $API_ID \
--parent-id $PARENT_ID \
--path-part $PATH_PART \
--query 'id' --output text)

awslocal apigateway put-method \
--rest-api-id $API_ID \
--resource-id $RESOURCE_ID \
--http-method $HTTP_METHOD \
--authorization-type "NONE" >/dev/null

awslocal apigateway put-integration \
--rest-api-id $API_ID \
--resource-id $RESOURCE_ID \
Expand All @@ -220,7 +220,7 @@ log "Deploying API..."
awslocal apigateway create-deployment \
--rest-api-id $API_ID \
--stage-name test >/dev/null
API_ENDPOINT="http://localhost:4566/_aws/execute-api/$API_ID/test/_user_request_"
API_ENDPOINT="http://localhost:4566/_aws/execute-api/$API_ID/test"
log "API deployed. Endpoint: $API_ENDPOINT"

# SQS DLQ -> EventBridge Pipes -> SNS
Expand Down Expand Up @@ -348,7 +348,7 @@ LAMBDA_PERMISSIONS=(

for PERMISSION_INFO in "${LAMBDA_PERMISSIONS[@]}"; do
read FUNCTION_NAME HTTP_METHOD PATH_PART <<< "$PERMISSION_INFO"

log "Adding permission for $FUNCTION_NAME to be invoked by API Gateway..."
awslocal lambda add-permission \
--function-name ${FUNCTION_NAME} \
Expand Down
4 changes: 2 additions & 2 deletions bin/seed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ if [ -z "$API_ID" ]; then
exit 1
fi

API_ENDPOINT="$AWS_ENDPOINT_URL/_aws/execute-api/$API_ID/test/_user_request_"
API_ENDPOINT="$AWS_ENDPOINT_URL/_aws/execute-api/$API_ID/test"

create_quiz() {
local quiz_data=$1
local response=$(curl -s -X POST "$API_ENDPOINT/createquiz" \
-H "Content-Type: application/json" \
-d "$quiz_data")

if [ "$(echo $response | jq -r 'has("QuizID")')" = "true" ]; then
local quiz_id=$(echo $response | jq -r '.QuizID')
log "Created quiz with ID: $quiz_id"
Expand Down
2 changes: 1 addition & 1 deletion frontend/scripts/populate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if [ -z "$API_ID" ]; then
exit 1
fi

API_ENDPOINT="$AWS_ENDPOINT_URL/_aws/execute-api/$API_ID/test/_user_request_"
API_ENDPOINT="$AWS_ENDPOINT_URL/_aws/execute-api/$API_ID/test"

echo "REACT_APP_API_ENDPOINT=$API_ENDPOINT" > .env.local

Expand Down
2 changes: 1 addition & 1 deletion tests/test_infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def api_endpoint():
raise Exception(f"API {API_NAME} not found.")

API_ID = api['id']
API_ENDPOINT = f"http://localhost:4566/_aws/execute-api/{API_ID}/test/_user_request_"
API_ENDPOINT = f"http://localhost:4566/_aws/execute-api/{API_ID}/test"

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

Expand Down
6 changes: 3 additions & 3 deletions tests/test_outage.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def api_endpoint(apigateway_client):
raise Exception(f"API {API_NAME} not found.")

API_ID = api['id']
API_ENDPOINT = f"{LOCALSTACK_ENDPOINT}/_aws/execute-api/{API_ID}/test/_user_request_"
API_ENDPOINT = f"{LOCALSTACK_ENDPOINT}/_aws/execute-api/{API_ID}/test"

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

Expand All @@ -38,11 +38,11 @@ def api_endpoint(apigateway_client):

def test_dynamodb_outage(api_endpoint):
outage_rule = FaultRule(region="us-east-1", service="dynamodb")

# Using fault_configuration context manager to apply and automatically clean up the fault rule
with fault_configuration(fault_rules=[outage_rule]):
print("DynamoDB outage initiated within context.")

# Attempt to create a quiz during the outage
create_quiz_payload = {
"Title": "Outage Test Quiz",
Expand Down

0 comments on commit 4ba0e2e

Please sign in to comment.