0

I'm facing an issue where I'm unable to create domain mappings for my App Engine Project via the API. Whenever I attempt to map a custom domain and automatically provision an SSL certificate, I encounter a 500 error with the message "Internal error encountered."

I'm using Python Flask Application and the googleapiclient library to interact with the App Engine API. The rest of my application is still working fine.

Here's a snippet of my code:

def create_domain_mapping(domain_name):
    try:
        credentials = get_credentials()
        if not credentials:
            logging.error("Failed to retrieve credentials.")
            return None

        app_id = os.getenv('app_id')
        if not app_id:
            logging.error("App ID is not set.")
            return None

        service = build('appengine', 'v1', credentials=credentials)
        app_name = f"apps/{app_id}"
        domain_body = {
            "name": "apps/{app_id}/domainMapping/{domain_name}",
            "id": domain_name
            # "sslSettings": {
            #     "sslManagementType": "AUTOMATIC"
            #}
        }
   
        response = service.apps().domainMappings().create(appsId=app_name, body=domain_body).execute()
        logging.info(f"SUCCESS - Domain mapping response : {response}")
        return response
    
    except Exception as e:
        logging.error(f"Failed to provision SSL : {e}")
        return None

Error Logs Image

For this issue, I've already taken the following steps to troubleshoot:

  • Verified service account permissions: Ensured the service account has the necessary App Engine Admin and Project Viewer roles.

  • Checked App Engine logs: There are no other related error messages.

  • Tested network connectivity: Confirmed network connectivity to Google Cloud services.

  • Checked quotas: Verified that I haven't exceeded any App Engine quotas.

  • Rewritten API call: Tried different variations of the API call to create domain mappings. In the code below, I even commented out the SSL provisioning just to test the domain mapping.

  • DNS Settings: I've made sure that the domain I'm trying to map also has the right A/CNAME records in DNS so it points to my application

  • Manual Mapping in GCloud: I've added the domain manually to see if there was an issue and it worked successfully.

  • Other error: When the SSL data is included in the API call, I also get the error: "INFO:Compute Engine Metadata server call to universe/universe_domain returned 404, reason: 404 page not found". I don't have this path explicitly called anywhere in my application.

Updated Snippet (still not working):

def create_domain_mapping(domain_name):
    try:
        credentials = get_credentials()
        if not credentials:
            logging.error("Failed to retrieve credentials")
            return None

        app_id = os.getenv('app_id')
        if not app_id:
            logging.error("App ID is not set")
            return None
        
        client = appengine_admin.AppEngineAdminClient(credentials=credentials)
        domain_mapping = {
            "domainName": domain_name,
            "sslSettings": {
                "sslManagementType": "AUTOMATIC"
            }
        }

        parent = f"projects/{app_id}/apps/{app_id}"
        response = client.create_domain_mapping(
            parent=parent,
            domain_mapping=domain_mapping
        )
  
        print(f"Domain mapping created: {response.name}")
        return response
    
    except Exception as e:
        logging.error(f"Failed to create domain mapping: {e}")
        return None

1 Answer 1

0
  1. Google says the googleapiclient library is in maintenance mode and they recommend you switch to the cloud client libraries. For domain mapping, that would be appengine admin library

  2. This is a link to sample code template for creating domain mapping using the appengine-admin library for python. The payload should be like this

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for your reply! I tried this API and it's still giving me this error: "INFO:google.auth.compute_engine._metadata: Compute Engine Metadata server call to universe/universe_domain returned 404, reason: 404 page not found" I am not explicitly referencing this path anywhere and any API I use for domain mapping gives me this error. I explicitly made a call to the server to make sure my App Engine instance can access the Metadata server and that was successful. So, I'm at a loss again - unsure of what's happening with the APIs.
Show your updated code. If you're testing this from your dev/local environment, then gcloud needs an application default credentials
I updated my post to show the updated code. My understanding is that I have App Default Creds since I've attached a service account to my local dev environment. I believe I wouldn't have been able to make an explicit test call to the GCE Metadata Server if the credentials had a fault, correct?
Well, try using the sample code from Google (the link in my response). Their sample code initializes a DomainMappingsClient which is what is used in making calls.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.