Reputation: 31
I'm looking the way to get a Project ID of GCP, running on AI Platform Custom Prediction
My project has 3 project that has dev, stage and prod, each project has to access unique URL from inside of custom prediction. And custom prediction codes are controlled by a single project.
I've tried gcloud
command running with subprocess
but It didn't work for me.
Upvotes: 0
Views: 308
Reputation: 31
I had same problem, where I needed the project name, went with following code
PROJECT_ID = ast.literal_eval(os.getenv('create_version_request')).get('parent').split('/', 2)[1]
print(f'PROJECT_ID={PROJECT_ID}', flush=True)
Upvotes: 0
Reputation: 31
I found that project number has a relationship with project id and os.environ.get("consumer_project_number")
can get a value of project number in Custom Prediction.
This is my final code to get Project ID.
if consumer_project_number == "hoge_1":
return "prd_ID"
elif consumer_project_number == "hoge_2":
return "stg_ID"
elif consumer_project_number == "hoge_3":
return "dev_ID"
else:
raise ValueError("None consumer_project_number detected.")
Upvotes: 1