title: gcloud app deploy - updating service default fails with code 13 Quota for instances limit exceeded, and 401 unathorizeed
body: <p>Created a new project, on first deploy I get this:</p>
  
  <pre><code>    Updating service [default] (this may take several minutes)...failed.                                                                                                       
  ERROR: (gcloud.app.deploy) Error Response: [13] Flex operation projects/primalexchange/regions/us-east1/operations/b5a5813a-14bf-43b6-af7f-e17b15866c4f error [INTERNAL]: An internal error occurred while processing task /appengine-flex-v1/insert_flex_deployment/flex_create_resources&gt;2020-05-16T23:23:08.373Z4721.jc.14: Deployment Manager operation primalexchange/operation-1589671388926-5a5cc367252d6-eae4c5cb-bc5f1a6e errors: [code: "RESOURCE_ERROR"
  location: "/deployments/aef-default-20200516t192110/resources/aef-default-20200516t192110"
  message: "{\"ResourceType\":\"compute.beta.regionAutoscaler\",\"ResourceErrorCode\":\"403\",\"ResourceErrorMessage\":{\"code\":403,\"errors\":[{\"domain\":\"usageLimits\",\"message\":\"Exceeded limit \'QUOTA_FOR_INSTANCES\' on resource \'aef-default-20200516t192110\'. Limit: 8.0\",\"reason\":\"limitExceeded\"}],\"message\":\"Exceeded limit \'QUOTA_FOR_INSTANCES\' on resource \'aef-default-20200516t192110\'. Limit: 8.0\",\"statusMessage\":\"Forbidden\",\"requestPath\":\"https://compute.googleapis.com/compute/beta/projects/primalexchange/regions/us-east1/autoscalers\",\"httpMethod\":\"POST\"}}"
  </code></pre>
  
  <p>The build in the builder shows as a completed success. </p>
  
  <p>It shows under versions that I have one version, with 0 instances, 100% traffic allocation, and when you click on the version it takes you to my site showing a 404 error.</p>
  
  <p>Probably because it says that service is stopped, and that's probably because it didn't 'update'. </p>
  
  <p>I don't think this is a 'my code' thing, 'cause I did a git checkout of a version that I once deployed under a different project successfully that basically amounts to a hello world app and while it once succeeded, it is now failing. Furthermore, I had another working deployment under the same project just a couple of days ago, but when I went to deploy with updated code, the deployment failed, with this very error, 'causing me to delete the entire project and start over, and now I'm getting the same error on this new project. How do I know it wasn't my code that caused the issue in the first place? I've had a build that failed because of my code and the logs of the build give that away. Here the build succeeds. there are no failures in the build. </p>
  
  <p>So I've gone to this url <a href="https://compute.googleapis.com/compute/beta/projects/primalexchange/regions/us-east1/autoscalers" rel="nofollow noreferrer">https://compute.googleapis.com/compute/beta/projects/primalexchange/regions/us-east1/autoscalers</a>
  which states this:</p>
  
  <pre><code>{
    "error": {
      "code": 401,
      "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
      "errors": [
        {
          "message": "Login Required.",
          "domain": "global",
          "reason": "required",
          "location": "Authorization",
          "locationType": "header"
        }
      ],
      "status": "UNAUTHENTICATED"
    }
  }
  </code></pre>
  
  <p>and I don't know if that's my problem or something else. I don't even know what that means really. so I made sure I've got creds at 'projectid.json' 
  and did
  export GOOGLE_APPLICATION_CREDENTIALS='projectid-2c8anumber842b4.json'</p>
  
  <p>and i disconnected code related to my firebase login stuff.</p>
  
  <p>I did these commands</p>
  
  <pre><code>gcloud services enable servicemanagement.googleapis.com
  gcloud services enable servicecontrol.googleapis.com
  gcloud services enable endpoints.googleapis.com
  </code></pre>
  
  <p>I don't know how to fix this issue. I've been trying to fix it all weekend.</p>
  
  <p>I when to Quota's under IAM, and looked at the quota for autoscalers in us-east1 and I found this which is not over anything:
  <a href="https://i.stack.imgur.com/clC3u.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/clC3u.png" alt="enter image description here"></a></p>
  
  <p>and the only thing with a limit of 8 is cpu's and it says I'm at 2.</p>
  
  <p>I don't know what I'm messing up..</p>
  
  <p>yes, billing is enabled.</p>
  
  <p>I just ran across this, which maybe this will get me some place...
  <a href="https://i.stack.imgur.com/L0T2m.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/L0T2m.png" alt="enter image description here"></a></p>
  
  <p>What's an authorization header? And why didn't I need that the first time.. or what have I messed up this time.</p>
  
  <p>And I changed my code so that all you get is a misspelling of hello world and it's still failing on deploy:</p>
  
  <pre><code>import logging
  
  from flask import Flask, jsonify, redirect, url_for
  from flask import request, make_response
  from flask import render_template
  from image_upload import upload_blob
  
  from google.cloud import storage
  from google.cloud import datastore
  
  
  from datetime import datetime
  from cryptography.fernet import Fernet
  
  from models.media import Media
  from models.user import User
  
  
  from google.cloud import ndb
  
  import json
  
  import random
  from uuid import uuid4
  
  from flask import Flask, make_response, request
  from google.auth.transport import requests
  import google.oauth2.id_token
  # from google.cloud import firestore
  
  from flask_wtf.csrf import CSRFProtect, generate_csrf
  from werkzeug.utils import secure_filename
  from werkzeug.exceptions import RequestEntityTooLarge
  
  @app.route('/', methods=['GET'])
  def hi():
      return "hellow world"
  
  
  @app.errorhandler(500)
  def server_error(e):
      logging.exception('An error occurred during a request.')
      return """
      An internal error occurred: &lt;pre&gt;{}&lt;/pre&gt;
      See logs for full stacktrace.
      """.format(e), 500
  
  
  if __name__ == '__main__':
      # This is used when running locally. Gunicorn is used to run the
      # application on Google App Engine. See entrypoint in app.yaml.
  
      app.run(host='127.0.0.1', port=8080, debug=True)
  </code></pre>
  
  <p>and now that I look at this more closely, how is this even running locally when I clearly have a double import of flask?</p>
  
  <p>I will try to deploy after removing that, but i doubt that's the issue I'll be back to publish another essay about this issue shortly.</p>
  
  <p>yeah that didn't matter. still failed.</p>
  
  <p>This image is from the third project I started. And I got it to deploy up until now.. where it's failing with the same error:</p>
  
  <p><a href="https://i.stack.imgur.com/tOtOF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tOtOF.png" alt="enter image description here"></a></p>
  
  <p>Here's the App.yaml</p>
  
  <pre><code>runtime: python
  api_version: '1'
  env: flexible
  threadsafe: true
  handlers:
    - url: /static/(.*)
      application_readable: true
      static_files: __static__/static/\1
      require_matching_file: false
      upload: __static__/static/.*
    - url: /.*
      script: main.app
      secure: never
  env_variables:
    SECRET_KEY: ____________
  automatic_scaling:
    cool_down_period: 120s
    min_num_instances: 2
    max_num_instances: 20
    cpu_utilization:
      target_utilization: 0.5
  network: {}
  liveness_check:
    initial_delay_sec: 300
    check_interval_sec: 30
    timeout_sec: 4
    failure_threshold: 4
    success_threshold: 2
  readiness_check:
    check_interval_sec: 5
    timeout_sec: 4
    failure_threshold: 2
    success_threshold: 2
    app_start_timeout_sec: 300
  </code></pre>
  
  <p>And it looks when I deploy I'm hitting an IP address in use limit of 4 when I checked the quota, and then it goes back down to 2 when I'm not. So maybe someone can advice me of how to set my app.yaml on how to avoid this? I don't know anything about scaling stuff so I wanted to do auto scaling and this app.yaml is basically default settings.</p>
  
  <p>Never mind. I had my quota increased to 6 and it still errors out.</p>