Files
aws-production/provision.bash
2025-06-27 20:31:23 +00:00

206 lines
5.3 KiB
Bash
Executable File

#!/bin/bash
# AWS CDK Ubuntu Setup Script
# This script installs all required software for AWS CDK development on Ubuntu
reset;clear
set -e # Exit on any error
echo "=========================================="
echo "AWS CDK Ubuntu Setup Script"
echo "=========================================="
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Update system packages
print_status "Updating system packages..."
sudo apt update && sudo apt upgrade -y
print_success "System packages updated"
# Install essential build tools and dependencies
print_status "Installing essential build tools..."
sudo apt install -y curl wget unzip git build-essential software-properties-common apt-transport-https ca-certificates gnupg lsb-release
print_success "Essential build tools installed"
# Install Node.js and npm using NodeSource repository (more reliable than nvm for scripts)
print_status "Installing Node.js and npm..."
if command_exists node; then
print_warning "Node.js is already installed ($(node --version))"
else
# Add NodeSource repository
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
print_success "Node.js $(node --version) and npm $(npm --version) installed"
fi
# Install Python 3 and pip
print_status "Installing Python 3 and pip..."
sudo apt install -y python3 python3-pip python3-venv python3-dev
print_success "Python $(python3 --version) and pip installed"
# Install AWS CLI v2
print_status "Installing AWS CLI v2..."
if command_exists aws; then
print_warning "AWS CLI is already installed ($(aws --version))"
else
cd /tmp
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip -q awscliv2.zip
sudo ./aws/install
# Add to PATH if needed
if ! command_exists aws; then
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bashrc
export PATH="/usr/local/bin:$PATH"
fi
cd - > /dev/null
print_success "AWS CLI $(aws --version) installed"
fi
# Install AWS CDK
print_status "Installing AWS CDK globally..."
if command_exists cdk; then
print_warning "AWS CDK is already installed ($(cdk --version))"
print_status "Upgrading AWS CDK to latest version..."
sudo npm install -g aws-cdk@latest
else
sudo npm install -g aws-cdk
fi
print_success "AWS CDK $(cdk --version) installed"
# Install TypeScript globally (optional but recommended)
print_status "Installing TypeScript globally..."
if command_exists tsc; then
print_warning "TypeScript is already installed ($(tsc --version))"
else
sudo npm install -g typescript
print_success "TypeScript $(tsc --version) installed"
fi
# Clean up temporary files
print_status "Cleaning up temporary files..."
rm -f /tmp/awscliv2.zip
sudo rm -rf /tmp/aws
print_success "Cleanup completed"
reset;clear
# Verify installations
echo ""
echo "=========================================="
echo "Installation Verification"
echo "=========================================="
print_status "Verifying installations..."
# Check Node.js
if command_exists node; then
print_success "Node.js: $(node --version)"
else
print_error "Node.js installation failed"
exit 1
fi
# Check npm
if command_exists npm; then
print_success "npm: $(npm --version)"
else
print_error "npm installation failed"
exit 1
fi
# Check Python
if command_exists python3; then
print_success "Python: $(python3 --version)"
else
print_error "Python installation failed"
exit 1
fi
# Check pip
if command_exists pip3; then
print_success "pip: $(pip3 --version)"
else
print_error "pip installation failed"
exit 1
fi
# Check AWS CLI
if command_exists aws; then
print_success "AWS CLI: $(aws --version)"
else
print_error "AWS CLI installation failed"
exit 1
fi
# Check CDK
if command_exists cdk; then
print_success "AWS CDK: $(cdk --version)"
else
print_error "AWS CDK installation failed"
exit 1
fi
# Check TypeScript
if command_exists tsc; then
print_success "TypeScript: $(tsc --version)"
else
print_warning "TypeScript not found (optional)"
fi
echo ""
echo "=========================================="
echo "Next Steps"
echo "=========================================="
echo ""
print_status "1. Configure AWS credentials:"
echo " aws configure"
echo ""
print_status "2. Create an EC2 Key Pair in AWS Console:"
echo " - Go to EC2 → Key Pairs → Create key pair"
echo " - Download the .pem file"
echo ""
print_status "3. Bootstrap CDK (replace with your account ID and region):"
echo " cdk bootstrap aws://123456789012/us-east-1"
echo ""
print_status "4. Create your CDK project:"
echo " mkdir my-cdk-project && cd my-cdk-project"
echo " cdk init app --language=typescript"
echo " # OR"
echo " cdk init app --language=python"
echo ""
print_success "AWS CDK setup completed successfully!"
echo ""
echo "=========================================="