How to connect to Cloud-SQL from Cloud Function in Go?How to configure postgresql for the first time?How to drop a PostgreSQL database if there are active connections to it?How to exit from PostgreSQL command line utility: psqlUnable to Connect Google App Engine and Google Cloud SQLTrouble connecting to Google Cloud SQL server from deployed appConnecting to Google Cloud SQL from WaveMaker OnlineApp Maker and Cloud SQL - connection issueDoes Enterprise DB can be migrated to Cloud SQL from Google Cloud?Connect google data studio to google cloud sqlGCP cloud function is unable to connect to GCP SQL instance
Helping ease my back pain when I'm studying 13 hours everyday, even weekends
Are birchat hoda'ah on the idea or the thing?
Non-flat partitions of a set
Can Ogre clerics use Purify Food and Drink on humanoid characters?
.NET executes a SQL query and Active Monitor shows multiple rows blocking each other
Parameterize chained calls to a utility program in Bash
Why do all the teams that I have worked with always finish a sprint without completion of all the stories?
Why is it recommended to mix yogurt starter with a small amount of milk before adding to the entire batch?
Greeting with "Ho"
Why don't countries like Japan just print more money?
Heavily limited premature compiler translates text into excecutable python code
Can White Castle?
Is "Busen" just the area between the breasts?
Why do some professors with PhDs leave their professorships to teach high school?
Why are < or > required to use /dev/tcp
Do I have to explain the mechanical superiority of the player-character within the fiction of the game?
What size of powerbank will I need to power a phone and DSLR for 2 weeks?
Prime sieve in Python
Are all instances of trolls turning to stone ultimately references back to Tolkien?
How large would a mega structure have to be to host 1 billion people indefinitely?
Is it illegal to withhold someone's passport and green card in California?
How many people are necessary to maintain modern civilisation?
Does a vocal melody have any rhythmic responsibility to the underlying arrangement in pop music?
What is the legal status of travelling with methadone in your carry-on?
How to connect to Cloud-SQL from Cloud Function in Go?
How to configure postgresql for the first time?How to drop a PostgreSQL database if there are active connections to it?How to exit from PostgreSQL command line utility: psqlUnable to Connect Google App Engine and Google Cloud SQLTrouble connecting to Google Cloud SQL server from deployed appConnecting to Google Cloud SQL from WaveMaker OnlineApp Maker and Cloud SQL - connection issueDoes Enterprise DB can be migrated to Cloud SQL from Google Cloud?Connect google data studio to google cloud sqlGCP cloud function is unable to connect to GCP SQL instance
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
For a project i'm trying to connection a cloud function to a cloud sql database setup as described in this quickstart guide.
The function is configured in the same region, the service account has the Role Cloud SQL-Client
. I called the function through my computer like this:
gcloud functions call <function-name> --region=<region> --data '"recipient":"hello","requester":"hello","message":"test"'
The connection to the function is working, it seems like just the authentication to the database doesn't work but i don't get where i failed.
I checked the password, user and connection name multiple times, reset the password and it still doesn't work.
I found the issue here related to connecting cloud functions to cloud sql.
I tried surrounding the password in the dsn
-string with single-quotes just to be sure escaping of characters in the password isn't a problem.
I also checked the environment variables coming in and they are the ones i entered in the configuration.
The function just pings the database for test purposes:
package receiver
import (
"database/sql"
"fmt"
"net/http"
"os"
// Import Postgres SQL driver
_ "github.com/lib/pq"
)
// Receives a message and stores it
func Receive(w http.ResponseWriter, r *http.Request)
connectionName := os.Getenv("POSTGRES_INSTANCE_CONNECTION_NAME")
dbUser := os.Getenv("POSTGRES_USER")
dbPassword := os.Getenv("POSTGRES_PASSWORD")
dsn := fmt.Sprintf("user=%s password='%s' host=/cloudsql/%s dbname=messages", dbUser, dbPassword, connectionName)
var err error
db, err := sql.Open("postgres", dsn)
if err != nil
fmt.Fprintf(w, "Could not open db: %v n", err)
// Only allow 1 connection to the database to avoid overloading
db.SetMaxIdleConns(1)
db.SetMaxOpenConns(1)
defer db.Close()
if pingerror := db.Ping(); pingerror != nil
fmt.Fprintf(w, "Failed to ping database: %s n", pingerror)
return
The variable POSTGRES_INSTANCE_CONNECTION_NAME
is formatted as described here as ProjectID:Region:InstanceID
.
Expected is a success message or no error and i'm actually getting this message:
pq: password authentication failed for user "postgres"
Note: I also created a function containing the demo code from here with my sql database settings and the error is the same. It seems like i missed some step while setting up the user or sql instance. But i can't find out which.
postgresql go google-cloud-functions google-cloud-sql
add a comment |
For a project i'm trying to connection a cloud function to a cloud sql database setup as described in this quickstart guide.
The function is configured in the same region, the service account has the Role Cloud SQL-Client
. I called the function through my computer like this:
gcloud functions call <function-name> --region=<region> --data '"recipient":"hello","requester":"hello","message":"test"'
The connection to the function is working, it seems like just the authentication to the database doesn't work but i don't get where i failed.
I checked the password, user and connection name multiple times, reset the password and it still doesn't work.
I found the issue here related to connecting cloud functions to cloud sql.
I tried surrounding the password in the dsn
-string with single-quotes just to be sure escaping of characters in the password isn't a problem.
I also checked the environment variables coming in and they are the ones i entered in the configuration.
The function just pings the database for test purposes:
package receiver
import (
"database/sql"
"fmt"
"net/http"
"os"
// Import Postgres SQL driver
_ "github.com/lib/pq"
)
// Receives a message and stores it
func Receive(w http.ResponseWriter, r *http.Request)
connectionName := os.Getenv("POSTGRES_INSTANCE_CONNECTION_NAME")
dbUser := os.Getenv("POSTGRES_USER")
dbPassword := os.Getenv("POSTGRES_PASSWORD")
dsn := fmt.Sprintf("user=%s password='%s' host=/cloudsql/%s dbname=messages", dbUser, dbPassword, connectionName)
var err error
db, err := sql.Open("postgres", dsn)
if err != nil
fmt.Fprintf(w, "Could not open db: %v n", err)
// Only allow 1 connection to the database to avoid overloading
db.SetMaxIdleConns(1)
db.SetMaxOpenConns(1)
defer db.Close()
if pingerror := db.Ping(); pingerror != nil
fmt.Fprintf(w, "Failed to ping database: %s n", pingerror)
return
The variable POSTGRES_INSTANCE_CONNECTION_NAME
is formatted as described here as ProjectID:Region:InstanceID
.
Expected is a success message or no error and i'm actually getting this message:
pq: password authentication failed for user "postgres"
Note: I also created a function containing the demo code from here with my sql database settings and the error is the same. It seems like i missed some step while setting up the user or sql instance. But i can't find out which.
postgresql go google-cloud-functions google-cloud-sql
add a comment |
For a project i'm trying to connection a cloud function to a cloud sql database setup as described in this quickstart guide.
The function is configured in the same region, the service account has the Role Cloud SQL-Client
. I called the function through my computer like this:
gcloud functions call <function-name> --region=<region> --data '"recipient":"hello","requester":"hello","message":"test"'
The connection to the function is working, it seems like just the authentication to the database doesn't work but i don't get where i failed.
I checked the password, user and connection name multiple times, reset the password and it still doesn't work.
I found the issue here related to connecting cloud functions to cloud sql.
I tried surrounding the password in the dsn
-string with single-quotes just to be sure escaping of characters in the password isn't a problem.
I also checked the environment variables coming in and they are the ones i entered in the configuration.
The function just pings the database for test purposes:
package receiver
import (
"database/sql"
"fmt"
"net/http"
"os"
// Import Postgres SQL driver
_ "github.com/lib/pq"
)
// Receives a message and stores it
func Receive(w http.ResponseWriter, r *http.Request)
connectionName := os.Getenv("POSTGRES_INSTANCE_CONNECTION_NAME")
dbUser := os.Getenv("POSTGRES_USER")
dbPassword := os.Getenv("POSTGRES_PASSWORD")
dsn := fmt.Sprintf("user=%s password='%s' host=/cloudsql/%s dbname=messages", dbUser, dbPassword, connectionName)
var err error
db, err := sql.Open("postgres", dsn)
if err != nil
fmt.Fprintf(w, "Could not open db: %v n", err)
// Only allow 1 connection to the database to avoid overloading
db.SetMaxIdleConns(1)
db.SetMaxOpenConns(1)
defer db.Close()
if pingerror := db.Ping(); pingerror != nil
fmt.Fprintf(w, "Failed to ping database: %s n", pingerror)
return
The variable POSTGRES_INSTANCE_CONNECTION_NAME
is formatted as described here as ProjectID:Region:InstanceID
.
Expected is a success message or no error and i'm actually getting this message:
pq: password authentication failed for user "postgres"
Note: I also created a function containing the demo code from here with my sql database settings and the error is the same. It seems like i missed some step while setting up the user or sql instance. But i can't find out which.
postgresql go google-cloud-functions google-cloud-sql
For a project i'm trying to connection a cloud function to a cloud sql database setup as described in this quickstart guide.
The function is configured in the same region, the service account has the Role Cloud SQL-Client
. I called the function through my computer like this:
gcloud functions call <function-name> --region=<region> --data '"recipient":"hello","requester":"hello","message":"test"'
The connection to the function is working, it seems like just the authentication to the database doesn't work but i don't get where i failed.
I checked the password, user and connection name multiple times, reset the password and it still doesn't work.
I found the issue here related to connecting cloud functions to cloud sql.
I tried surrounding the password in the dsn
-string with single-quotes just to be sure escaping of characters in the password isn't a problem.
I also checked the environment variables coming in and they are the ones i entered in the configuration.
The function just pings the database for test purposes:
package receiver
import (
"database/sql"
"fmt"
"net/http"
"os"
// Import Postgres SQL driver
_ "github.com/lib/pq"
)
// Receives a message and stores it
func Receive(w http.ResponseWriter, r *http.Request)
connectionName := os.Getenv("POSTGRES_INSTANCE_CONNECTION_NAME")
dbUser := os.Getenv("POSTGRES_USER")
dbPassword := os.Getenv("POSTGRES_PASSWORD")
dsn := fmt.Sprintf("user=%s password='%s' host=/cloudsql/%s dbname=messages", dbUser, dbPassword, connectionName)
var err error
db, err := sql.Open("postgres", dsn)
if err != nil
fmt.Fprintf(w, "Could not open db: %v n", err)
// Only allow 1 connection to the database to avoid overloading
db.SetMaxIdleConns(1)
db.SetMaxOpenConns(1)
defer db.Close()
if pingerror := db.Ping(); pingerror != nil
fmt.Fprintf(w, "Failed to ping database: %s n", pingerror)
return
The variable POSTGRES_INSTANCE_CONNECTION_NAME
is formatted as described here as ProjectID:Region:InstanceID
.
Expected is a success message or no error and i'm actually getting this message:
pq: password authentication failed for user "postgres"
Note: I also created a function containing the demo code from here with my sql database settings and the error is the same. It seems like i missed some step while setting up the user or sql instance. But i can't find out which.
postgresql go google-cloud-functions google-cloud-sql
postgresql go google-cloud-functions google-cloud-sql
edited Mar 25 at 18:22
MoBlaa
asked Mar 25 at 8:21
MoBlaaMoBlaa
115
115
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Feels strange to answer my own question but here it is: For some reason connecting with the postgres
user doesn't work. Finally i created a new database user for the function and a password containing only alphanumeric characters.
Hey, good job on finding the solution to your question. As soon as you can, please mark it as solution to give more visibility to the question.
– Andrei Cusnir
Mar 26 at 10:04
add a comment |
The unix socket at /cloudsql/connectionName
is only provided in the GCF runtime. When running locally, you either need change your connection string or use the Cloud SQL proxy to simulate a unix socket at the same path.
I tested with the emulator and proxy already and hat no success and i already created the function in the gcloud console and am still receiving the same error.
– MoBlaa
Mar 25 at 18:11
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55333681%2fhow-to-connect-to-cloud-sql-from-cloud-function-in-go%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Feels strange to answer my own question but here it is: For some reason connecting with the postgres
user doesn't work. Finally i created a new database user for the function and a password containing only alphanumeric characters.
Hey, good job on finding the solution to your question. As soon as you can, please mark it as solution to give more visibility to the question.
– Andrei Cusnir
Mar 26 at 10:04
add a comment |
Feels strange to answer my own question but here it is: For some reason connecting with the postgres
user doesn't work. Finally i created a new database user for the function and a password containing only alphanumeric characters.
Hey, good job on finding the solution to your question. As soon as you can, please mark it as solution to give more visibility to the question.
– Andrei Cusnir
Mar 26 at 10:04
add a comment |
Feels strange to answer my own question but here it is: For some reason connecting with the postgres
user doesn't work. Finally i created a new database user for the function and a password containing only alphanumeric characters.
Feels strange to answer my own question but here it is: For some reason connecting with the postgres
user doesn't work. Finally i created a new database user for the function and a password containing only alphanumeric characters.
answered Mar 26 at 8:21
MoBlaaMoBlaa
115
115
Hey, good job on finding the solution to your question. As soon as you can, please mark it as solution to give more visibility to the question.
– Andrei Cusnir
Mar 26 at 10:04
add a comment |
Hey, good job on finding the solution to your question. As soon as you can, please mark it as solution to give more visibility to the question.
– Andrei Cusnir
Mar 26 at 10:04
Hey, good job on finding the solution to your question. As soon as you can, please mark it as solution to give more visibility to the question.
– Andrei Cusnir
Mar 26 at 10:04
Hey, good job on finding the solution to your question. As soon as you can, please mark it as solution to give more visibility to the question.
– Andrei Cusnir
Mar 26 at 10:04
add a comment |
The unix socket at /cloudsql/connectionName
is only provided in the GCF runtime. When running locally, you either need change your connection string or use the Cloud SQL proxy to simulate a unix socket at the same path.
I tested with the emulator and proxy already and hat no success and i already created the function in the gcloud console and am still receiving the same error.
– MoBlaa
Mar 25 at 18:11
add a comment |
The unix socket at /cloudsql/connectionName
is only provided in the GCF runtime. When running locally, you either need change your connection string or use the Cloud SQL proxy to simulate a unix socket at the same path.
I tested with the emulator and proxy already and hat no success and i already created the function in the gcloud console and am still receiving the same error.
– MoBlaa
Mar 25 at 18:11
add a comment |
The unix socket at /cloudsql/connectionName
is only provided in the GCF runtime. When running locally, you either need change your connection string or use the Cloud SQL proxy to simulate a unix socket at the same path.
The unix socket at /cloudsql/connectionName
is only provided in the GCF runtime. When running locally, you either need change your connection string or use the Cloud SQL proxy to simulate a unix socket at the same path.
answered Mar 25 at 15:43
kurtisvgkurtisvg
866212
866212
I tested with the emulator and proxy already and hat no success and i already created the function in the gcloud console and am still receiving the same error.
– MoBlaa
Mar 25 at 18:11
add a comment |
I tested with the emulator and proxy already and hat no success and i already created the function in the gcloud console and am still receiving the same error.
– MoBlaa
Mar 25 at 18:11
I tested with the emulator and proxy already and hat no success and i already created the function in the gcloud console and am still receiving the same error.
– MoBlaa
Mar 25 at 18:11
I tested with the emulator and proxy already and hat no success and i already created the function in the gcloud console and am still receiving the same error.
– MoBlaa
Mar 25 at 18:11
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55333681%2fhow-to-connect-to-cloud-sql-from-cloud-function-in-go%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown