Using the Python Google API client library from AppEngine flex, I'm making calls to GCP ML Engine API. It works fine when I list the different models, get their default version and all "read-only" actions but when I try to create a new version for a model, it does not work. I get a 403 Forbidden error with "Access to model denied".
I use a service account to make the calls. In IAM, my service account has the "ML Engine administrator" right.
This is how I make the call
from google.oauth2.service_account import Credentials
credentials = Credentials.from_service_account_file(PATH_TO_MY_JSON)
ml_client = discovery.build(u'ml', u'v1', credentials=credentials)
body = {
u"name": version_name,
u"description": description,
u"runtimeVersion": current_default_version.get(u"runtimeVersion"),
u"framework": current_default_version.get(u"framework"),
u"pythonVersion": current_default_version.get(u"pythonVersion"),
u"deploymentUri": deployment_uri
}
request = ml_client.projects().models().versions().create(parent=get_query_name(model_name), body=body)
request.execute()
The error
<HttpError 403 when requesting https://ml.googleapis.com/v1/projects/XXX/models/YYY/versions?alt=json returned "Access to model denied.">
it has to do with the service account because when I run this code in Cloud Shell and build my ml_client
without credentials (ml_client = discovery.build(u'ml', u'v1')
), it works fine.