Search code examples
pycharmgoogle-cloud-rungoogle-cloud-intellijgoogle-cloud-code

How to specify GOOGLE_APPLICATION credentials when using Intellij Cloud Code Cloud Run locally?


PyCharm's Cloud Code plugin will let me run and deploy Google Cloud Run services. However, when I try to set up a local configuration, I am not sure how to specify my Google Application Credentials.

I know how to mount this via the command line using docker run, but I don't know how to specify the service account. There is a "service account" field, in which I have input both the path to the key file, as well as the email address of the service account (neither work)

enter image description here


Solution

  • I'm a Developer Advocate with the Cloud Code team. Without knowing the error you're getting, it's hard to tell if this is an IAM or auth config issue.

    In the config, adding the email address of your service account to the "Service Account" field should do the trick here.

    I just tested this by doing the following:

    1. Create a new Python Flask Cloud Run project using a starter template Cloud Code provides.
    2. Edit the Cloud Run: Run Locally config's "Service Account" field to include the email address of my service account. Note that I gave this service account Owner permission for testing.
    3. Add in a Cloud Translate snippet https://cloud.google.com/translate/docs/advanced/translating-text-v3#translating_input_strings
    4. Run the Cloud Run: Run locally configuration

    Once the service was running, I opened the URL in the Event Log and the translate API was called successfully.

    Alternatively, you could add your service account's key.json file to your project, create a new environment variable in your Dockerfile named GOOGLE_APPLICATION_CREDENTIALS, and set that variable equal to the path of your key.json file.

    Reference:

    https://cloud.google.com/code/docs/intellij/developing-a-cloud-run-app https://cloud.google.com/run/docs/configuring/service-accounts