This documentation is for Magento 1.x. For Magento 2.x, see here.
At the time of writing, Cloud Functions only supports three runtimes: Node.js 6, Node.js 8, and Python 3.7.

Example: Clean Visitor Logs

This example shows how to use Cloud Functions to clean the visitor logs from Magento.



To use the Python runtime, two files are required: and requirements.txt. You can download them here:

mkdir -pv visitor_log_clean && \
curl -fsL \
     > ./visitor_log_clean/ && \
curl -fsL \
     > ./visitor_log_clean/requirements.txt


Clean the database of visitor log entries using Cloud Functions.


  1. Create visitor_log_clean cloud function

    The following environment variables are required for Cloud Functions to access Cloud SQL:

    • DB_NAME: The name of the Magento database.
    • DB_USER: The name of the database user.
    • DB_PASS: The database user's password.
    • PROJECT_ID: The Google Cloud Platform project ID.
    • REGION_ID: The region where the Cloud SQL instance exists (e.g. us-central1, us-east4).
    • INSTANCE_NAME: The name of Cloud SQL instance.

    Using gcloud, run the following:

      gcloud functions deploy visitor_log_clean
                              --entry-point="log_clean" \
                              --runtime=python37 \
                              --source="./visitor_log_clean" \

    Alternatively, you can use the Cloud Functions interface. Click Create Function from the list overview, and specify the following:

    • Name: visitor_log_clean
    • Memory: 256MB
    • Trigger: HTTP
    • Source code: Inline editor
    • Runtime: Python 3.7
    • Contents of from above
    • requirements.txt: Contents of requirements.txt from above
    • Function to execute: log_clean

    Next, click More and set each of the environment variables listed above. Then click Create.

  2. Add entry to <crontab>

    To make use of visitor_log_clean from within Magento, you will need to add the following to your module config.xml file:

                <cron_expr>30 2 * * *</cron_expr>

    Alternatively, you can use Aoe_Scheduler to create and schedule cron jobs. It's a substantially nicer solution and it provides a ton of additional benefits.