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:
- Create a new Python Flask Cloud Run project using a starter template Cloud Code provides.
- 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.
- Add in a Cloud Translate snippet https://cloud.google.com/translate/docs/advanced/translating-text-v3#translating_input_strings
- 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