Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ To tail logs in real-time:

```sh
# Example: Get logs for {{service-name}}
awslocal logs tail /aws/lambda/{{function-name}} \
--follow --format short --color on
AWS_ENDPOINT_URL="http://localhost:4566" \
aws logs tail /aws/lambda/{{function-name}} \
--follow --format short --color on
```

Replace `{{function-name}}` with corresponding service name
Expand Down
2 changes: 0 additions & 2 deletions bin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,7 @@ Sets up the complete local development environment on Ubuntu 22.04.
* Installs Docker (Container runtime)
* Installs LocalStack (AWS service emulation)
* Installs AWS CLI v2 (AWS command-line tools)
* Installs awslocal (AWS CLI wrapper for LocalStack)
* Installs Terraform (Infrastructure as Code)
* Installs tflocal (Terraform wrapper for LocalStack)
* Installs PostgreSQL (Relational database)
* Installs MongoDB (NoSQL database)
* Optionally: Installs and configures dnsmasq (DNS resolution)
Expand Down
2 changes: 0 additions & 2 deletions bin/deploy-backend.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo ""
echo "Requirements:"
echo " - terraform installed"
echo " - tflocal installed (for local development)"
echo " - ENVIRONMENT.config file (auto-created for AWS)"
echo ""
echo "Examples:"
Expand All @@ -40,7 +39,6 @@ export PATH="$HOME/.local/bin:$PATH"
export AWS_REGION=${AWS_REGION:-us-east-1}

# Verify required dependencies
tflocal --version > /dev/null 2>&1 || { echo "ERROR: 'tflocal' is missing. Aborting..."; exit 1; }
terraform --version > /dev/null 2>&1 || { echo "ERROR: 'terraform' is missing. Aborting..."; exit 1; }

# Resolve script directory and project root paths
Expand Down
32 changes: 12 additions & 20 deletions bin/deploy-frontend.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Requirements:"
echo " - aws cli installed"
echo " - npm installed"
echo " - terraform/tflocal installed"
echo " - terraform installed"
echo " - Backend infrastructure deployed first"
echo ""
echo "Examples:"
Expand All @@ -39,7 +39,6 @@ echo ""
# Verify required dependencies
aws --version > /dev/null 2>&1 || { echo "ERROR: 'aws' is missing. Aborting..."; exit 1; }
npm --version > /dev/null 2>&1 || { echo "ERROR: 'npm' is missing. Aborting..."; exit 1; }
tflocal --version > /dev/null 2>&1 || { echo "ERROR: 'tflocal' is missing. Aborting..."; exit 1; }
terraform --version > /dev/null 2>&1 || { echo "ERROR: 'terraform' is missing. Aborting..."; exit 1; }

# Resolve script directory and project root paths
Expand All @@ -52,9 +51,6 @@ FRONTEND_DIR="$PROJECT_ROOT/frontend"
INFRA_DIR="$PROJECT_ROOT/infra"
ENVIRONMENT=${1:-"aws"}

# Select terraform command (terraform or tflocal)
TF_CMD="terraform"

# Set up PATH and AWS region
export PATH="$HOME/.local/bin:$PATH"
export AWS_REGION=${AWS_REGION:-us-east-1}
Expand All @@ -76,24 +72,20 @@ if [ "$ENVIRONMENT" = "aws" ]; then
fi
else
# Local development configuration
if command -v tflocal > /dev/null 2>&1; then
TF_CMD="tflocal"
else
# Fallback to terraform with local endpoint
export AWS_ENDPOINT_URL="http://localhost:4566"
fi
export AWS_ENDPOINT_URL="http://localhost:4566"
export AWS_ENDPOINT_URL_S3="http://s3.localhost.localstack.cloud:4566"

# Set dummy AWS credentials for local development
export AWS_ACCESS_KEY_ID=test
export AWS_SECRET_ACCESS_KEY=test
AWS_ENDPOINT="--endpoint-url=http://localhost:4566"
BUCKET_NAME="coding-workshop-tfstate-${PARTICIPANT_ID:-abcd1234}"
if ! aws s3 ls | grep -q "$BUCKET_NAME"; then
aws s3 mb "s3://$BUCKET_NAME"
fi
fi

# Change to infrastructure directory
cd "$INFRA_DIR"

# Retrieve S3 bucket name from Terraform outputs
BUCKET_NAME=$($TF_CMD output -raw s3_bucket_name 2>/dev/null || echo "")
BUCKET_NAME=$(terraform output -raw s3_bucket_name 2>/dev/null || echo "")
echo "INFO: Target bucket - $BUCKET_NAME"

# Verify S3 bucket exists (indicates backend infrastructure is deployed)
Expand All @@ -104,9 +96,9 @@ if [ -z "$BUCKET_NAME" ]; then
fi

# Retrieve API configuration from Terraform outputs
API_BASE_URL=$($TF_CMD output -raw api_base_url 2>/dev/null || echo "")
API_BASE_URL=$(terraform output -raw api_base_url 2>/dev/null || echo "")
echo "INFO: API Base URL - $API_BASE_URL"
API_ENDPOINTS=$($TF_CMD output -json api_endpoints 2>/dev/null || echo "{}")
API_ENDPOINTS=$(terraform output -json api_endpoints 2>/dev/null || echo "{}")
echo "INFO: API Endpoints - $API_ENDPOINTS"

# Local Development: Skip frontend build (use start-dev.sh instead)
Expand Down Expand Up @@ -165,7 +157,7 @@ if [ "$ENVIRONMENT" = "aws" ]; then
cd "$INFRA_DIR"

# Retrieve CloudFront distribution ID from Terraform outputs
DISTRIBUTION_ID=$($TF_CMD output -raw cloudfront_distribution_id 2>/dev/null || echo "")
DISTRIBUTION_ID=$(terraform output -raw cloudfront_distribution_id 2>/dev/null || echo "")

# Create cache invalidation for all files
if [ -n "$DISTRIBUTION_ID" ]; then
Expand All @@ -180,7 +172,7 @@ echo "INFO: Frontend deployment complete!"

# Display CloudFront URL
cd "$INFRA_DIR"
URL=$($TF_CMD output -raw website_url 2>/dev/null || echo "")
URL=$(terraform output -raw website_url 2>/dev/null || echo "")

if [ -n "$URL" ]; then
echo ""
Expand Down
2 changes: 1 addition & 1 deletion bin/generate-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo " -h, --help Show this help message"
echo ""
echo "Requirements:"
echo " - terraform or tflocal installed"
echo " - terraform installed"
echo " - Backend infrastructure deployed"
echo ""
echo "Output:"
Expand Down
66 changes: 1 addition & 65 deletions bin/setup-environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# - Browser: Google Chrome
# - Containers: Docker (with sudo-less access)
# - Cloud Tools: Terraform CLI, AWS CLI v2
# - LocalStack: LocalStack CLI, tflocal, awslocal
# - LocalStack: LocalStack CLI
# - Database: PostgreSQL, pgAdmin
# - Database: MongoDB, MongoDB Compass
# - Runtimes: Node.js, Python
Expand Down Expand Up @@ -93,7 +93,6 @@ Installed tools:
- Terraform CLI
- AWS CLI v2
- LocalStack CLI
- tflocal, awslocal
- PostgreSQL with pgAdmin
- MongoDB with MongoDB Compass
- Node.js
Expand Down Expand Up @@ -1272,65 +1271,6 @@ EOF
fi
}

install_tflocal() {
print_section "tflocal (terraform-local)"

if is_dry_run; then
print_dry_run_header "TFLOCAL" "tflocal (terraform-local)"
if command -v tflocal &> /dev/null || [ -f "$ACTUAL_HOME/.local/bin/tflocal" ]; then
print_dry_run_status "Already installed"
else
print_dry_run_missing "Not installed"
print_dry_run_action "Would install: terraform-local (via pip3)"
print_dry_run_action "Would update PATH in ~/.bashrc"
fi
return
fi

print_info "Installing tflocal..."

# Idempotency check
if command -v tflocal &> /dev/null || [ -f "$ACTUAL_HOME/.local/bin/tflocal" ]; then
print_info "tflocal already installed"
return
fi

if python3 -m pip install terraform-local; then
print_status "tflocal installed"
else
add_failure "Failed to install tflocal"
fi
}

install_awslocal() {
print_section "awslocal (awscli-local)"

if is_dry_run; then
print_dry_run_header "AWSLOCAL" "awslocal (awscli-local)"
if command -v awslocal &> /dev/null || [ -f "$ACTUAL_HOME/.local/bin/awslocal" ]; then
print_dry_run_status "Already installed"
else
print_dry_run_missing "Not installed"
print_dry_run_action "Would install: awscli-local (via pip3)"
fi
return
fi

print_info "Installing awslocal..."

# Idempotency check
if command -v awslocal &> /dev/null || [ -f "$ACTUAL_HOME/.local/bin/awslocal" ]; then
print_info "awslocal already installed"
return
fi

if python3 -m pip install awscli-local; then
print_status "awslocal installed"
else
add_failure "Failed to install awslocal"
fi
}

# ============================================================================
# SECTION 13: DNSMASQ CONFIGURATION (OPTIONAL)
# ============================================================================
Expand Down Expand Up @@ -1472,8 +1412,6 @@ run_verification() {

# LocalStack
verify_tool "LocalStack" "localstack --version"
verify_tool_path "tflocal" "$ACTUAL_HOME/.local/bin/tflocal"
verify_tool_path "awslocal" "$ACTUAL_HOME/.local/bin/awslocal"

# Database
verify_tool "MongoDB" "mongod --version" "grep 'db version'"
Expand Down Expand Up @@ -1793,8 +1731,6 @@ main() {
install_terraform
install_awscli
install_localstack
install_tflocal
install_awslocal
configure_dnsmasq

# Verification and summary
Expand Down
18 changes: 7 additions & 11 deletions bin/start-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo " - mongod installed"
echo " - npm installed"
echo " - localstack installed"
echo " - tflocal installed"
exit 0
fi

Expand All @@ -43,6 +42,10 @@ PROJECT_ROOT="$(cd $SCRIPT_DIR/.. > /dev/null 2>&1 || exit 1; pwd -P)"
INFRA_DIR="$PROJECT_ROOT/infra"
FRONTEND_DIR="$PROJECT_ROOT/frontend"

# Ensure local development
export AWS_ENDPOINT_URL="http://localhost:4566"
export AWS_ENDPOINT_URL_S3="http://s3.localhost.localstack.cloud:4566"

# ============================================================
# STEP 1: Check and Start PostgreSQL
# ============================================================
Expand Down Expand Up @@ -300,13 +303,6 @@ echo ""
# ============================================================
echo -e "[4/5] Checking Backend Infrastructure..."

# Verify required tools
if ! command -v tflocal &> /dev/null; then
echo -e "ERROR: tflocal is not installed"
echo "Install: pip install terraform-local"
exit 1
fi

# Detect MongoDB host for LocalStack Lambda functions
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
export TF_VAR_mongodb_host="172.17.0.1"
Expand All @@ -327,9 +323,9 @@ rm -rf "$INFRA_DIR/builds"

# Check if backend is deployed
BACKEND_OK=false
if tflocal output lambda_urls > /dev/null 2>&1; then
if terraform output lambda_urls > /dev/null 2>&1; then
# Backend is deployed, verify functions are accessible
LAMBDA_URLS=$(tflocal output -json lambda_urls 2>/dev/null | grep -o 'http://[^"]*' | head -1 || echo "")
LAMBDA_URLS=$(terraform output -json lambda_urls 2>/dev/null | grep -o 'http://[^"]*' | head -1 || echo "")

if [ -n "$LAMBDA_URLS" ]; then
# Test if at least one function responds
Expand Down Expand Up @@ -357,7 +353,7 @@ fi

# Display Lambda URLs
echo -e " Lambda Function URLs:"
tflocal output -json lambda_urls 2>/dev/null | grep -o 'http://[^"]*' | sed 's/^/ /' || echo " (none)"
terraform output -json lambda_urls 2>/dev/null | grep -o 'http://[^"]*' | sed 's/^/ /' || echo " (none)"

echo ""

Expand Down
5 changes: 3 additions & 2 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ To tail backend logs in real-time:

```sh
# Example: Get logs for {{service-name}}
awslocal logs tail /aws/lambda/{{function-name}} \
--follow --format short --color on
AWS_ENDPOINT_URL="http://localhost:4566" \
aws logs tail /aws/lambda/{{function-name}} \
--follow --format short --color on
```

Replace `{{function-name}}` with corresponding service name
Expand Down
20 changes: 17 additions & 3 deletions infra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,28 @@ To run your application locally:
localstack start -d
```

Make sure that AWS APIs are accessible locally:

```sh
export AWS_ENDPOINT_URL="http://localhost:4566"
export AWS_ENDPOINT_URL_S3="http://s3.localhost.localstack.cloud:4566"
```

To deploy infrastructure locally:

```sh
cd infra
rm -rf .terraform*
tflocal init -backend-config bucket=coding-workshop-us-east-1-abcd1234
tflocal apply -var aws_app_code=abcd1234
terraform init -backend-config bucket=coding-workshop-us-east-1-abcd1234
terraform apply -var aws_app_code=abcd1234
```

**Note:** Replace `abcd1234` from above with your participant id shared by workshop organizer(s).

After successful execution, view outputs:

```sh
tflocal output
terraform output
```

### Cloud Deployment
Expand All @@ -66,6 +73,13 @@ To setup participant environment:
./bin/setup-participant.sh
```

Make sure that AWS APIs are accessible remotely:

```sh
unset AWS_ENDPOINT_URL
unset AWS_ENDPOINT_URL_S3
```

To deploy your infrastructure to AWS:

```sh
Expand Down
Loading