Error connecting GCP App Engine to GCP SQL - google-app-engine

I'm trying to deploy a Flask App on the App Engine, but I'm getting this error about the database connection:
sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2003,
"Can't connect to MySQL server on 'localhost' ([Errno 111] Connection
refused)")
I'm doing the connection like this:
databaseUri = 'mysql+pymysql://user:pass#/database?unix_socket=/cloudsql/connection_name'
Also activated the Cloud SQL Administrator API as the documentation says, but not working
Does anyone have an idea about what am I missing or doing wrong?
I've have been stuck on this for 2 days and I can't make it work, thanks for your help.

I solved it.
I post the solution maybe helps someone else.
I still don't know why, but when running the command to deploy the app in the App Engine:
gcloud app deploy
It use by default the Compute Engine service account instead of the App Engine service account, so I just had to run the command specifying it to use the App Engine service account:
gcloud app deploy --service-account=SERVICE_ACCOUNT
Hope it helps any newbe like me.

Related

Deploy Google App Engine Failed Create VM

[Failed create VM][1]
Please help me to solve this problem. I'm deploying NodeJS Service to Google App Engine, but It's always fail like the attachments.
It said that failed create VM and the version deployed have no instance running
https://i.stack.imgur.com/YgxuH.png

Steps to setup angular app in Google Cloud App Engine and Go Daddy

I want to deploy an angular app is n Google Cloud Platform App Engine, and link to my domain in Go Daddy.
I have done the domain verification in Google, and able to do npm start in cloud shell and web preview it, however need help with below:
1. How to persist the deployment even if I close the shell? Adding & to make it a background process enough?
2. What should be the values in Go Daddy DNS configurations
3. If I deploy on another port, such as 4200, how to forward http, https, and www to that port?
Any help us much appreciated, thanks in advance.
When you do npm start in the Cloud Shell to web preview it you’re only running the app “locally” in Cloud Shell, you’re not actually deploying it to App Engine. To deploy your app you should use the gcloud app deploy command.
The general steps on how to deploy the app in App Engine are documented here
Regarding the DNS values to map your custom domain please follow the steps 4, 5 and 6 in this documentation
In order to understand how Port forwarding works in App Engine I recommend checking this document.
If you are interested there's also a codelab where you can go through all the steps on deploying an Angular app to App Engine.

Unable to create Google App Engine application

When I tried to create a Google App Engine application via gcloud app create at terminal on Ubuntu and on the web, it gives me the following error,
"ERROR: (gcloud.app.create) Error Response: [13] An internal error occurred while ensuring the default service account exists."
I guess the reason why I don't have the default service account because I deleted a default project on GCP which was made when I started using GCP, not sure though.
I made a service account at IAM & admin menu, but not work. Any idea?
Although I found this answer, it didn't work for me.
How to recover Google App Engine's "default service account"
But I didn't delete the default google app engine service account, it was missing at the first place. Maybe because I tried to create a GAE app on the web and left the page before it's done. I don't know.
Anyway, I make a new project and create a GAE app via gcloud cli, and now it's good to go.

Application Default Credentials not working locally with App Engine

Having a tough time getting the Default Application Credentials to load in the dataflow SDK when running locally in a java app engine project developing on OS X. Runs fine when deployed.
According to this the dev app server doesn't support them, and you're meant to use the gcloud command line tool's command: gcloud preview app run - but according to the official Google Group for the SDK here that command was deprecated in Jan 2016.
So I seem to be stuck between a rock and a hard place... Does anyone know how to get the Application Default Credentials to work locally with an App Engine app?
I'm trying to use the Dataflow API and it just throws up when it starts making use of the cloud storage api which is the first thing the Pipeline does because it can't seem to load the correct credentials from the environment variables ( that are definitely set on the ENV and in the appengine-web.xml <env-variables> element ) or from the ~/.config/cloud/default_application_credentials.json file.
Cheers!
Can you try running the following command and see if it solves it?
gcloud auth application-default login
This is fully supported (but poorly documented) within the dev appserver. There is a very well answered question that gives you step by step instructions here: Unable to access BigQuery from local App Engine development server

Using remote data store on Google App Engine

I am trying to use the remote data store on Google App Engine on localhost, but I really can't get it to work.
I have tried following this advice Remote_api configuration with App Engine which does seem to handle the first request and uses the remote datastore (I think), but on the subsequent request it does not, and I get the error:
"BadRequestError: app s~myapp cannot access app dev~myapp's data"
I have also tried the following:
BadRequestError: app s~myapphr cannot access app dev~myapphr's data. Why?
Google App Engine trying to access dev data
and a lot of other suggestions, but without any luck.
Any ideas on how to use the remote datastore on localhost ?
thanks
Thomas

Resources