I tried to upload a simple hello world application to the app engine. I managed to upload one flask application but when I tried to navigate the link that provided by GCP I got 502 bad gatway Nginx. Then I tried to deploy again new app with new version and I got this error:
ERROR: (gcloud.app.deploy) PERMISSION_DENIED: The version cannot run because it is unable to generate an access token for the target service account [project-id]@appspot.gserviceaccount.com. Please check that your project has the App Engine Standard Service Agent role following "https://cloud.google.com/appengine/docs/standard/go/service-agent." This command is authenticated as [username with very strong permission] which is the active account specified by the [core/account] property.
I gave the necessary permission to everything.
I found that I don't have service-PROJECT_NUMBER@gcp-gae-service.iam.gserviceaccount.com service agent in my IAM.
I gave the predefined role App Engine standard environment Service Agent to the default service account --> [ProjectID]@appspot.gserviceaccount.com because I didn't found the service agent in my IAM
I tried to disable and enable the app engine service --> appengine.googleapis.com
appenginereporting.googleapis.com
I hope someone here will have the answer for this.
Thanks in advance.
The service agent for your Google Cloud project is automatically created after you deploy your first service—for example, after you run the gcloud app deploy command for the first time to deploy an app in the standard environment.
According to the documentation (see above quote), the role grant should be automatic.
Sometimes it takes a bit of time which means you simply wait and then retry.