Executing shell commands (lam.shell)

lam.shell is a secure shell execution system that allows you to safely execute bash shell commands while providing the ability to chain together any type of business logic. This system enables you to build complex workflows by combining shell commands with control flow mechanisms and configuration management.

1

Basic lam.shell Step Structure

(data) => {
    const script = `#!/bin/bash
    set -e
    
    echo "Hello from lam.shell"
    ls -la /data/
    `;
    
    return {
        "lam.shell": {
            "script": script,
            "timeout": 300
        }
    };
}
2

File Processing Step with Binary Data

(data) => {
    const fileNames = data.input.files || [];
    
    const script = `#!/bin/bash
    set -e
    
    echo "Processing ${fileNames.length} zip files..."
    
    # List available files
    ls -al /data/input/
    
    # Process each zip file
    for file in /data/input/*.zip; do
        if [ -f "$file" ]; then
            filename=$(basename "$file" .zip)
            echo "Extracting $filename..."
            
            # Create extraction directory
            mkdir -p "/data/output/$filename"
            
            # Extract zip file
            unzip "$file" -d "/data/output/$filename"
            
            # List extracted contents
            echo "Contents of $filename:"
            ls -la "/data/output/$filename"
        fi
    done
    
    echo "File processing completed"
    `;
    
    return {
        "lam.shell": {
            "script": script,
            "binaryDataIds": data.step_6.response, // Pass binary data IDs
            "environment": {
                "SFDX_DISABLE_AUTOUPDATE": "true",
                "SFDX_USE_GENERIC_UNIX_KEYCHAIN": "true"
            },
            "timeout": 600
        }
    };
}
3

Configuration-Driven Step

(data) => {
    const script = `#!/bin/bash
    set -e
    
    # Use configuration values
    API_URL="{{config.apiUrl}}"
    API_KEY="{{config.apiKey}}"
    BATCH_SIZE="{{config.batchSize}}"
    
    echo "Starting data processing with batch size: $BATCH_SIZE"
    
    # Validate configuration
    if [ -z "$API_URL" ]; then
        echo "Error: API URL not configured"
        exit 1
    fi
    
    # Process data in batches
    TOTAL_RECORDS=$(wc -l < /data/input/data.csv)
    BATCHES=$(( (TOTAL_RECORDS + BATCH_SIZE - 1) / BATCH_SIZE ))
    
    echo "Processing $TOTAL_RECORDS records in $BATCHES batches"
    
    for ((i=1; i<=BATCHES; i++)); do
        START_LINE=$(( (i-1) * BATCH_SIZE + 1 ))
        END_LINE=$(( i * BATCH_SIZE ))
        
        echo "Processing batch $i (lines $START_LINE-$END_LINE)"
        
        # Extract batch
        sed -n "${START_LINE},${END_LINE}p" /data/input/data.csv > /tmp/batch_$i.csv
        
        # Send batch to API
        curl -X POST "$API_URL/batch" \
             -H "Authorization: Bearer $API_KEY" \
             -H "Content-Type: text/csv" \
             --data-binary @/tmp/batch_$i.csv \
             -o /data/output/batch_${i}_response.json
        
        # Clean up temp file
        rm /tmp/batch_$i.csv
    done
    
    echo "Batch processing completed"
    `;
    
    return {
        "lam.shell": {
            "script": script,
            "environment": {
                "CURL_CA_BUNDLE": "/etc/ssl/certs/ca-certificates.crt"
            },
            "timeout": 1800
        }
    };
}

Last updated

Was this helpful?