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:
Disclaimer: This is not an official Google product, always test thoroughly before deploying to live systems.
How It Works
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.
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!