Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Migrating and Deploying Apigee Resources Across Organizations

When working with Apigee, you might find yourself needing to move API proxies, shared flows, apps, developers, etc between different organizations, potentially as part of a migration, testing, or staging process. 

While a one-click full-organization snapshot and deployment feature isn't directly available, the apigeecli command-line interface offers a robust way to automate the export, import, and deployment of your API proxies and shared flows across different Apigee organizations.

I've created a simple script that lets you quickly export a snapshot of your Apigee organization and deploy it to a new environment or organization. This script can be a valuable addition to your toolkit, especially when you need to:

  • Create sandbox environments: Quickly spin up a replica of your production environment for testing or development.
  • Migrate between organizations: Move your API proxies and shared flows to a different Apigee organization.
  • Disaster recovery: Have a reliable backup in case of accidental deletions or configuration errors.

Disclaimer: This is not an official Google product, always test thoroughly before deploying to live systems.

How It Works

  1. Export: The script creates a local backup of your Apigee resources (API proxies, shared flows, etc.).
  2. Deploy: You can then use the same script to deploy these resources to another Apigee environment or organization.
  3. Error Handling: The script includes robust error handling to catch and report any issues during deployment.

Script

 

 

#!/bin/bash

set -e

# Google Cloud authentication (uncomment if needed)
# gcloud auth application-default login

# Source and target Apigee organizations and deployment environment
export ORG_FROM=REPLACE
export ORG_TO=REPLACE
export DEPLOY=true
export ENV=REPLACE

# ---- Resource Export/Import ----

# Create backup directory
mkdir apigee_backup
cd apigee_backup

echo "Exporting resources in the organization $ORG_FROM ..."
apigeecli organizations export -o $ORG_FROM --default-token

echo "Importing resources in the organization $ORG_TO ..."
apigeecli organizations import -o $ORG_TO -f . --default-token


# ---- Deployment ----

set +e

failed_proxies=()
failed_sharedflows=()

if [ "$DEPLOY" = true ]; then

    # Input validation for deployment
    read -p "Are you sure you want to deploy to $ORG_TO in the $ENV environment? (y/n): " confirmation
    if [ "$confirmation" != "y" ]; then
        echo "Deployment canceled."
        exit 1  # Exit script with non-zero status to indicate cancellation
    fi

    echo "Deploying sharedflows..."
    for sharedflow in sharedflows/*.zip; do
        sharedflow_name=${sharedflow##*/}  # Extract filename from path
        sharedflow_name=${sharedflow_name%.*} # Remove file extension
        apigeecli sharedflows deploy -o "$ORG_TO" -e "$ENV" -n "$sharedflow_name" --default-token
        if [ $? -ne 0 ]; then
        echo "Error deploying sharedflow $sharedflow_name. Adding to list for manual review."
        failed_sharedflows+=("$sharedflow_name")
    fi
    done

    echo "Deploying proxies..."
    for proxy in proxies/*.zip; do
        proxy_name=${proxy##*/}  # Extract filename from path
        proxy_name=${proxy_name%.*} # Remove file extension
        apigeecli apis deploy -o "$ORG_TO" -e "$ENV" -n "$proxy_name" --default-token
        if [ $? -ne 0 ]; then
        echo "Error deploying $proxy_name. Adding to list for manual review."
        failed_proxies+=("$proxy_name")
    fi
    done

    if [ ${#failed_proxies[@]} -gt 0 ] || [ ${#failed_sharedflows[@]} -gt 0 ]; then
        echo "Deployment complete, but with errors. The following resources require manual intervention:"

        if [ ${#failed_proxies[@]} -gt 0 ]; then
            echo "Proxies:"
            for failed_proxy in "${failed_proxies[@]}"; do
                echo "- $failed_proxy"
            done
        fi
    
        if [ ${#failed_sharedflows[@]} -gt 0 ]; then
            echo "Sharedflows:"
            for failed_sharedflow in "${failed_sharedflows[@]}"; do
                echo "- $failed_sharedflow"
            done
        fi
    else
        echo "Deployment complete!"
    fi
else
    echo "DEPLOY variable not set to true. Skipping deployment."
fi

 

 

Feedback Welcome!

I'd love to hear your feedback and any suggestions for improvement. Please feel free to open issues or pull requests on the GitHub repository. Should you have issues with the apigeecli , you can open an issue here.

Please note: There's currently no way to directly migrate integrated portals using an API. However, you can still leverage the apigeecli tool to import apidocs/apicategories once you've manually created a new portal in the target organization. The exported resources will be located in the apigee_backup/portals directory after running the script.

 

3 1 269
1 REPLY 1

Hi @vmartucci, thank you for sharing these valuable steps and considerations for migrating and deploying Apigee resources across organizations! This kind of detailed information is incredibly helpful. Looking forward to seeing comments from the rest of the community!