Search code examples
google-cloud-functionsslack

GCP slack tutorial 'slash command'; failed to deploy google cloud function


When going through the tutorial for creating a basic slack app with google cloud, the deployment stage fails with:

>gcloud functions deploy kg_search --runtime python37 --trigger-http Deploying function (may take a while - up to 2 minutes)...failed. ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Function failed on loading user code. Error message: 'API_KEY'

Trying to figure out how to fix this


Solution

  • In line 29 the code os.environ['API_KEY'] is trying to fetch the API_KEY from shell environment variables but as it's undefined the program crashes. As you discovered, when you get rid of the first part of the or statement the exception is not raised anymore.

    The way to set environment variables when you deploy Google Cloud Functions is explained here.

    Could you retry the deployment step running gcloud functions deploy kg_search --set-env-vars API_KEY=YOUR-API-KEY --runtime python37 --trigger-http and see if it works that way?