How do i deploy a Perfect (swift) backend code + PostgreSQL to Google App Engine - swift

i'm pretty new to web development and much more in Google Cloud, sorry for anything.
Basically, i'm doing the backend part of an app in Swift (using Perfect), and it's running smoothly and okay in my local computer, i'm using a local Postgre database (using PostgreORM in my application).
But, when i deploy that to the Google Cloud, it does not recognize the database (i've created a identical poster database in the computer engine AND a Cloud SQL (Postgre service of Google Cloud with the same names and credentials), but again, when the app is on the cloud, it does not recognize the database, what i'm missing? How should i do it? Install other docker image with Postgre?
Here's my DBConnector code:
import PostgresStORM
func setupDBCredentials() -> PostgresConnector.Type{
let connection = PostgresConnector.self
connection.host = "localhost" // or the connection name of the Google Cloud, it doesn't work as well
connection.username = "postgres"
connection.password = "nearby"
connection.database = "nearby"
connection.port = 5432
return connection
}
Basically, how do i make my google app engine code connect to any database at all?
Also, if it helps, i'm using the Perfect Assistant to deploy my code to Google Cloud, using Docker.
Thanks already!

You'll likely need to do a few things to get connected, such as granting access to the Cloud SQL instance. Here is the link to the PHP docs that cover the broad steps that you'll want to follow and it shows a representation of the connection string that you'll also need.
I believe your connection string needs to look something like this
pgsql:dbname=DATABASE;host=/cloudsql/CONNECTION_NAME
Where CONNECTION_NAME is in the format of PROJECT_ID:CLOUD_SQL_REGION_ID:CLOUD_SQL_INSTANCE_ID

Related

Connecting Postgres instance to AppEngine - Google Cloud, with SpringBoot

I've nearly got a SpringBoot app running on Google Cloud services that is connected to a Postgres instance.
I've ran through the steps on their guide, located here and have gotten to the point where I need to set my variables up for the app to find the database instance:
The problem encountered is two fold:
I don't know where and how to set these
My server logs report this error:
meaning that the Spring application is trying to find the database like it would on my local.
I set the following values in the app.yaml (assuming this is where they should be?)
runtime: java11
instance_class: F1
env_variables:
SQL_USER: quickstart-user
SQL_PASSWORD: <password>
SQL_DATABASE: quickstart_db
INSTANCE_CONNECTION_NAME: quickstart-instance
So, my question(s) are:
Is this the correct place to set them?
If not, do I need a appengine-web.xml file instead (And does anyone have an example of what this looks like, I can't find one)
How do I stop the app from looking for the local database?
Thanks

Vue3 and Supabase when connecting via Remote device I get "WebSocket connection to 'ws://localhost:4000/ws' failed: "

I am using a Nuxt3 server currently running in develop mode that uses a Supabase Database and when I try to connect to the server from a diffrent device then my localhost I get a constant error of "WebSocket connection to 'ws://localhost:4000/ws' failed: " in the develop console.
I want this error to stop because I have a diffrent problem and want to rule out this error as a source for problems.
So far I didnt really try much because I just dont know where to start. I guess that it has something to do with Supabases Postgres database, but I am quite new to Vue3 and Supabase so I dont know if a URL needs to be configured diffrently.
Appreciate it if someone with more knowlede could help me!
Update:
This is how the error looks on a remote device
And this is how it looks on the local device
For Nuxt my Package.json looks like this
And my nuxt.config.ts looks like this
Additional information that might be usefull:
I store the supabase url and key in a .env file and when I use supabase I do it with:
const user = useSupabaseUser()
const client = useSupabaseClient()
The error always occures when I try to access the website by using the Network URL provided by the yarn dev command. It happens on mobile devices aswell as other computers

Use AWS Amplify and App Sync with existing Node Server using Mongodb

Currently, I'm developing a native application using React-Native. I've decided to go with AWS Amplify because of it's real time updates as well as its authentication.
I also have a Web Application that runs on a Node.js with Epxress server. This web application connects to a Mongo database.
My big problem is that I would like to have all of my aws amplify queries run to my existing MongoDb instead of a new dynamoDb database which is provided with AWS AppSync, but unfortunately I dont know where to start. This is especially helpful in adding authentication easily in my existing web application as well.
My first idea was to just create all my API endpoints in a new node js server and have app sync call to these API end points, but I'm not sure how to implement calling end points on an existing server (and this seems kind of counter intuitive to the 'serverless' idea)
My other idea came from this: Can AWS App-Sync be used without dynamoDB
This states to use AWS Lambda to 'pipeline' my data to the existing mongodb, but I'm not really sure what that entails.
TL;DR - I would like to be able to query an existing Mongodb instead of using DynamoDb when using AWS Amplify with AppSync.
I hope this is clear enough and doesn't sound like I'm rambling. Thanks in advance!
I would suggest using either an HTTP datasource to connect to your MongoDB backend or a Lambda function. Here are a couple getting started tutorials for both:
https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-http-resolvers.html
https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-lambda-resolvers.html
If you go the Lambda route, then you can leverage the new #function feature of the GraphQL Transformer in the Amplify CLI: https://aws-amplify.github.io/docs/cli/graphql#function

Google App Engine PHP PDO connection fails 'MySQL server has gone away'

So I've setup two different GAE app projects, in the primary app i've created two Cloud SQL instances. I've granted access to my other app on both SQL instances.
When I attempt a simple PDO connection from the app which does not contain the cloud sql instances (live on GAE) I receive this error: SQLSTATE[HY000] [2006] MySQL server has gone away
here is the PHP connection line as per the GAE docs:
$db = new pdo('mysql:unix_socket=/cloudsql/<app-id>:<sql-instance-name>;dbname=<db-name>', 'root', '');
Connecting via IP from my local GAE SDK instance works as expected.
Any suggestions would be great!
So far I've tried:
increasing the max_allowed_packet size 32000
increasing the long_query_time to 60
increasing the wait_timeout to 60
The google app engine documentation states:
"Google Cloud Platform project called <your-project-id> is connecting to a Cloud SQL instance named <your-instance-name>."
You're probably getting an error because for project id you are using the project Id for your appengine application, not your Cloud SQL project ID.
Try:
$db = new pdo('mysql:unix_socket=/cloudsql/<sql-project-id>:<sql-instance-name>;dbname=<db-name>', 'root', '');
In the Cloud Console's Instance Details, under Properties toward the bottom of the screen, there's a field called Instance connection name. So what worked for me was:
$db = new pdo('mysql:unix_socket=/cloudsql/<instance-connection-name>;dbname=<db-name>', 'root', '');
This happened to me today, the problem for me was the app-id, make sure it includes the whole Google Apps domain. e.g. if your app is testapp, your instance is instancetest and your domain is domain.com the complete statement is:
$db = new pdo('mysql:unix_socket=/cloudsql/domain.com:testapp:instancetest;dbname=testdb', 'root', '');
Hope it helps.

Scala Lift - Connect to remote MongoDB

I currently have my app running on my local machine, in Boot.scala I have:
MongoDB.defineDb(
DefaultMongoIdentifier,
MongoAddress(MongoHost("127.0.0.1", 27017), "platform")
)
I've successfully deployed the app to a cloud provider, and am in the process of setting up a database # mongohq.com
What would I need to change to enable the app to connect? I've taken a look here:
https://www.assembla.com/wiki/show/liftweb/Mongo_Configuration
But am a little confused by the connection details provided by mongohq, all they provide is:
Mongo URI
mongodb://<user>:<password>#<host>:<port>/<my_account_name>
Thanks in advance for any help, much appreciated :)
I am not familiar with MongoHQ in particular, but you should be able to put something in Boot like this:
MongoDB.defineDbAuth(
DefaultMongoIdentifier,
new Mongo(new ServerAddress("<host>", <port>)),
<my_account_name>,
<user>,
<pass>
)
Where the <*> variables are the particular part of the connection URI that were provided to you when you signed up for MongoHQ.