Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- build_layers.sh +126 -0
- python312_install.sh +130 -0
build_layers.sh
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# Build AWS Lambda Layers for WhatsApp Handler
|
| 4 |
+
set -e
|
| 5 |
+
|
| 6 |
+
echo "π Building AWS Lambda Layers..."
|
| 7 |
+
|
| 8 |
+
# Colors for output
|
| 9 |
+
RED='\033[0;31m'
|
| 10 |
+
GREEN='\033[0;32m'
|
| 11 |
+
YELLOW='\033[1;33m'
|
| 12 |
+
NC='\033[0m' # No Color
|
| 13 |
+
|
| 14 |
+
# Function to print colored output
|
| 15 |
+
print_status() {
|
| 16 |
+
echo -e "${GREEN}[INFO]${NC} $1"
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
print_warning() {
|
| 20 |
+
echo -e "${YELLOW}[WARNING]${NC} $1"
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
print_error() {
|
| 24 |
+
echo -e "${RED}[ERROR]${NC} $1"
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
# Check if Python 3.12 is available
|
| 28 |
+
if ! command -v python3.12 &> /dev/null; then
|
| 29 |
+
print_error "Python 3.12 is not installed"
|
| 30 |
+
exit 1
|
| 31 |
+
fi
|
| 32 |
+
|
| 33 |
+
print_status "Python version: $(python3.12 --version)"
|
| 34 |
+
|
| 35 |
+
# Create base directories
|
| 36 |
+
print_status "Creating layer directories..."
|
| 37 |
+
mkdir -p layers/wp_lambda_layer/python/lib/python3.12/site-packages
|
| 38 |
+
mkdir -p layers/wp_additional_layer/python/lib/python3.12/site-packages
|
| 39 |
+
mkdir -p layers/phonepe_layer/python/lib/python3.12/site-packages
|
| 40 |
+
|
| 41 |
+
# Install wp_lambda_layer dependencies
|
| 42 |
+
print_status "Installing wp_lambda_layer dependencies..."
|
| 43 |
+
pip3.12 install --no-cache-dir --target layers/wp_lambda_layer/python/lib/python3.12/site-packages \
|
| 44 |
+
requests==2.31.0 \
|
| 45 |
+
boto3==1.34.0 \
|
| 46 |
+
botocore==1.34.0 \
|
| 47 |
+
urllib3==1.26.18 \
|
| 48 |
+
certifi==2023.11.17 \
|
| 49 |
+
charset-normalizer==3.3.2 \
|
| 50 |
+
idna==3.6 \
|
| 51 |
+
jmespath==1.0.1 \
|
| 52 |
+
python-dateutil==2.8.2 \
|
| 53 |
+
s3transfer==0.10.0 \
|
| 54 |
+
six==1.16.0
|
| 55 |
+
|
| 56 |
+
# Install wp_additional_layer dependencies
|
| 57 |
+
print_status "Installing wp_additional_layer dependencies..."
|
| 58 |
+
pip3.12 install --no-cache-dir --target layers/wp_additional_layer/python/lib/python3.12/site-packages \
|
| 59 |
+
pg8000==1.30.4 \
|
| 60 |
+
scramp==1.4.4 \
|
| 61 |
+
asn1crypto==1.5.1
|
| 62 |
+
|
| 63 |
+
# Install PhonePe SDK
|
| 64 |
+
print_status "Installing PhonePe SDK..."
|
| 65 |
+
pip3.12 install --no-cache-dir --target layers/phonepe_layer/python/lib/python3.12/site-packages \
|
| 66 |
+
--index-url https://phonepe.mycloudrepo.io/public/repositories/phonepe-pg-sdk-python \
|
| 67 |
+
--extra-index-url https://pypi.org/simple \
|
| 68 |
+
phonepe_sdk==1.1.0
|
| 69 |
+
|
| 70 |
+
# Remove unnecessary files to reduce layer size
|
| 71 |
+
print_status "Cleaning up unnecessary files..."
|
| 72 |
+
find layers/ -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
|
| 73 |
+
find layers/ -type f -name "*.pyc" -delete 2>/dev/null || true
|
| 74 |
+
find layers/ -type f -name "*.pyo" -delete 2>/dev/null || true
|
| 75 |
+
find layers/ -type d -name "*.dist-info" -exec rm -rf {} + 2>/dev/null || true
|
| 76 |
+
find layers/ -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true
|
| 77 |
+
find layers/ -type f -name "*.so" -exec strip {} + 2>/dev/null || true
|
| 78 |
+
|
| 79 |
+
# Create zip files
|
| 80 |
+
print_status "Creating layer zip files..."
|
| 81 |
+
cd layers
|
| 82 |
+
|
| 83 |
+
# Create wp_lambda_layer.zip
|
| 84 |
+
print_status "Creating wp_lambda_layer.zip..."
|
| 85 |
+
cd wp_lambda_layer
|
| 86 |
+
zip -r ../wp_lambda_layer.zip . -x "*.pyc" "*/__pycache__/*"
|
| 87 |
+
cd ..
|
| 88 |
+
|
| 89 |
+
# Create wp_additional_layer.zip
|
| 90 |
+
print_status "Creating wp_additional_layer.zip..."
|
| 91 |
+
cd wp_additional_layer
|
| 92 |
+
zip -r ../wp_additional_layer.zip . -x "*.pyc" "*/__pycache__/*"
|
| 93 |
+
cd ..
|
| 94 |
+
|
| 95 |
+
# Create phonepe_layer.zip
|
| 96 |
+
print_status "Creating phonepe_layer.zip..."
|
| 97 |
+
cd phonepe_layer
|
| 98 |
+
zip -r ../phonepe_layer.zip . -x "*.pyc" "*/__pycache__/*"
|
| 99 |
+
cd ..
|
| 100 |
+
|
| 101 |
+
# Show file sizes
|
| 102 |
+
print_status "Layer sizes:"
|
| 103 |
+
du -sh wp_lambda_layer.zip wp_additional_layer.zip phonepe_layer.zip
|
| 104 |
+
|
| 105 |
+
# Verify layer structure
|
| 106 |
+
print_status "Verifying layer structure..."
|
| 107 |
+
echo "wp_lambda_layer contents:"
|
| 108 |
+
unzip -l wp_lambda_layer.zip | head -20
|
| 109 |
+
|
| 110 |
+
echo -e "\nwp_additional_layer contents:"
|
| 111 |
+
unzip -l wp_additional_layer.zip | head -20
|
| 112 |
+
|
| 113 |
+
echo -e "\nphonepe_layer contents:"
|
| 114 |
+
unzip -l phonepe_layer.zip | head -20
|
| 115 |
+
|
| 116 |
+
print_status "β
All layers created successfully!"
|
| 117 |
+
print_status "π¦ Layer files:"
|
| 118 |
+
ls -la *.zip
|
| 119 |
+
|
| 120 |
+
print_status "π Ready to upload to AWS Lambda!"
|
| 121 |
+
echo -e "\n${GREEN}Next steps:${NC}"
|
| 122 |
+
echo "1. Upload wp_lambda_layer.zip to AWS Lambda as a layer"
|
| 123 |
+
echo "2. Upload wp_additional_layer.zip to AWS Lambda as a layer"
|
| 124 |
+
echo "3. Upload phonepe_layer.zip to AWS Lambda as a layer"
|
| 125 |
+
echo "4. Add all three layers to your Lambda function"
|
| 126 |
+
echo "5. Set Python runtime to 3.12"
|
python312_install.sh
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# Install Python 3.12 on Amazon Linux (without sudo)
|
| 4 |
+
# This script attempts to install Python 3.12 in user space
|
| 5 |
+
|
| 6 |
+
set -e
|
| 7 |
+
|
| 8 |
+
echo "π Installing Python 3.12 for AWS Lambda Layers..."
|
| 9 |
+
|
| 10 |
+
# Colors for output
|
| 11 |
+
RED='\033[0;31m'
|
| 12 |
+
GREEN='\033[0;32m'
|
| 13 |
+
YELLOW='\033[1;33m'
|
| 14 |
+
NC='\033[0m' # No Color
|
| 15 |
+
|
| 16 |
+
print_status() {
|
| 17 |
+
echo -e "${GREEN}[INFO]${NC} $1"
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
print_warning() {
|
| 21 |
+
echo -e "${YELLOW}[WARNING]${NC} $1"
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
print_error() {
|
| 25 |
+
echo -e "${RED}[ERROR]${NC} $1"
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
# Check if we already have Python 3.12
|
| 29 |
+
if command -v python3.12 &> /dev/null; then
|
| 30 |
+
print_status "Python 3.12 is already available: $(python3.12 --version)"
|
| 31 |
+
exit 0
|
| 32 |
+
fi
|
| 33 |
+
|
| 34 |
+
# Try to install Python 3.12 using package manager first
|
| 35 |
+
print_status "Attempting to install Python 3.12 using package manager..."
|
| 36 |
+
|
| 37 |
+
# For Amazon Linux 2023
|
| 38 |
+
if [ -f /etc/os-release ]; then
|
| 39 |
+
source /etc/os-release
|
| 40 |
+
if [[ "$NAME" == *"Amazon Linux"* ]]; then
|
| 41 |
+
print_status "Detected Amazon Linux"
|
| 42 |
+
|
| 43 |
+
# Try with dnf (Amazon Linux 2023)
|
| 44 |
+
if command -v dnf &> /dev/null; then
|
| 45 |
+
print_status "Using dnf to install Python 3.12..."
|
| 46 |
+
dnf install -y python3.12 python3.12-pip python3.12-devel || {
|
| 47 |
+
print_warning "Failed to install Python 3.12 via dnf"
|
| 48 |
+
}
|
| 49 |
+
# Try with yum (Amazon Linux 2)
|
| 50 |
+
elif command -v yum &> /dev/null; then
|
| 51 |
+
print_status "Using yum to install Python 3.12..."
|
| 52 |
+
yum install -y python3.12 python3.12-pip python3.12-devel || {
|
| 53 |
+
print_warning "Failed to install Python 3.12 via yum"
|
| 54 |
+
}
|
| 55 |
+
fi
|
| 56 |
+
fi
|
| 57 |
+
fi
|
| 58 |
+
|
| 59 |
+
# Check if installation was successful
|
| 60 |
+
if command -v python3.12 &> /dev/null; then
|
| 61 |
+
print_status "β
Python 3.12 installed successfully: $(python3.12 --version)"
|
| 62 |
+
|
| 63 |
+
# Create symlinks if they don't exist
|
| 64 |
+
if [ ! -f /usr/bin/python3.12 ]; then
|
| 65 |
+
which python3.12 > /dev/null && ln -sf $(which python3.12) /usr/local/bin/python3.12 || true
|
| 66 |
+
fi
|
| 67 |
+
|
| 68 |
+
# Set alternatives
|
| 69 |
+
if command -v alternatives &> /dev/null; then
|
| 70 |
+
alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1 || true
|
| 71 |
+
alternatives --install /usr/bin/pip3 pip3 /usr/bin/pip3.12 1 || true
|
| 72 |
+
fi
|
| 73 |
+
|
| 74 |
+
exit 0
|
| 75 |
+
fi
|
| 76 |
+
|
| 77 |
+
# If package manager installation failed, try building from source
|
| 78 |
+
print_warning "Package manager installation failed. Attempting to build from source..."
|
| 79 |
+
|
| 80 |
+
# Create a local installation directory
|
| 81 |
+
PYTHON_HOME="$HOME/.local/python3.12"
|
| 82 |
+
mkdir -p $PYTHON_HOME
|
| 83 |
+
|
| 84 |
+
# Download Python 3.12 source
|
| 85 |
+
PYTHON_VERSION="3.12.2"
|
| 86 |
+
PYTHON_URL="https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz"
|
| 87 |
+
|
| 88 |
+
print_status "Downloading Python ${PYTHON_VERSION}..."
|
| 89 |
+
cd /tmp
|
| 90 |
+
wget $PYTHON_URL
|
| 91 |
+
tar -xzf Python-${PYTHON_VERSION}.tgz
|
| 92 |
+
cd Python-${PYTHON_VERSION}
|
| 93 |
+
|
| 94 |
+
# Configure and build
|
| 95 |
+
print_status "Configuring Python build..."
|
| 96 |
+
./configure --prefix=$PYTHON_HOME \
|
| 97 |
+
--enable-optimizations \
|
| 98 |
+
--enable-shared \
|
| 99 |
+
--with-ensurepip=install
|
| 100 |
+
|
| 101 |
+
print_status "Building Python (this may take a while)..."
|
| 102 |
+
make -j$(nproc)
|
| 103 |
+
|
| 104 |
+
print_status "Installing Python to ${PYTHON_HOME}..."
|
| 105 |
+
make install
|
| 106 |
+
|
| 107 |
+
# Create symlinks
|
| 108 |
+
ln -sf $PYTHON_HOME/bin/python3.12 $HOME/.local/bin/python3.12
|
| 109 |
+
ln -sf $PYTHON_HOME/bin/pip3.12 $HOME/.local/bin/pip3.12
|
| 110 |
+
|
| 111 |
+
# Add to PATH
|
| 112 |
+
echo "export PATH=$HOME/.local/bin:$PATH" >> $HOME/.bashrc
|
| 113 |
+
export PATH=$HOME/.local/bin:$PATH
|
| 114 |
+
|
| 115 |
+
# Verify installation
|
| 116 |
+
if command -v python3.12 &> /dev/null; then
|
| 117 |
+
print_status "β
Python 3.12 built and installed successfully!"
|
| 118 |
+
print_status "Version: $(python3.12 --version)"
|
| 119 |
+
print_status "Location: $(which python3.12)"
|
| 120 |
+
else
|
| 121 |
+
print_error "β Failed to install Python 3.12"
|
| 122 |
+
exit 1
|
| 123 |
+
fi
|
| 124 |
+
|
| 125 |
+
# Clean up
|
| 126 |
+
cd $HOME
|
| 127 |
+
rm -rf /tmp/Python-${PYTHON_VERSION}*
|
| 128 |
+
|
| 129 |
+
print_status "π Python 3.12 is ready to use!"
|
| 130 |
+
print_status "Run 'source ~/.bashrc' or restart your shell to update PATH"
|