The tutorial you linked was for the App Engine standard environment, which
is why it isn't working in the Flexible environment.  I would look over the
App Engine Flexible golang docs for Using CloudSQL
<https://cloud.google.com/appengine/docs/flexible/go/using-cloud-sql>, and
the App Engine Flexible python docs for Using CloudSQL Postgres
<https://cloud.google.com/appengine/docs/flexible/python/using-cloud-sql-postgres#setting_connection_strings_and_adding_a_library>.
I'll put in a request to add a sample for go, so this is an easier task to
just get started with.

I haven't tested this myself, but it looks like your connection should look
like:
db, err := sql.Open("postgres", fmt.Sprintf("%s:%s@%s?host=/cloudsql/%s",
user, password, database, connectionName))


On Thu, Jun 22, 2017 at 1:11 PM, Jason Lee <[email protected]> wrote:

> I *am *using App Engine flexible environment.
>
> Does this mean there's no way for me to connect to Google Cloud SQL from
> App Engine once deployed?
>
>
>
> On Thursday, 22 June 2017 13:03:22 UTC-7, joshuamo wrote:
>>
>> If you take a look at the CloudSQL Postgres documentation
>> <https://cloud.google.com/sql/docs/postgres/connect-app-engine>, you'll
>> see that App Engine standard is not yet supported.  Postgres on CloudSQL is
>> currently a beta product and isn't available for all environments at this
>> time.  You can, however, use a Postgres db on App Engine Flexible
>> environment.
>>
>> On Thu, Jun 22, 2017 at 12:44 PM, Jason Lee <[email protected]> wrote:
>>
>>> Tutorial link I am following is: https://cloud.google.com/a
>>> ppengine/docs/standard/go/cloud-sql/#setting-up
>>>
>>>
>>>
>>> On Thursday, 22 June 2017 12:25:56 UTC-7, Jason Lee wrote:
>>>>
>>>> I am trying to follow the tutorial at:
>>>>
>>>> And I am having the hardest time making my Google App Engine (GoLang)
>>>> connect to the Cloud SQL Postgres database. I am able to connect NOT
>>>> following the tutorial by manually opening the port from the firewall
>>>> rules. But I cannot do it this way because it's connected via IP and if I
>>>> do it this way, I cannot deploy to GAE.
>>>>
>>>> Could someone please review the following GoLang code to see what is
>>>> wrong.
>>>>
>>>> ```
>>>> *This following line is used to connect from localhost GoLang app to
>>>> Cloud SQL -- NOT FOLLOWING THE TUTORIAL*
>>>> db, err := sql.Open("postgres", host=IP_ADDRESS port=PORT user=USERNAME
>>>> password=PASSWORD dbname=DBNAME sslmode=disable)
>>>>
>>>> Here, I am connecting to the Cloud SQL postgres database by IP address.
>>>> I opened a port manually by firewall rule to make it accessible from my
>>>> local IP.
>>>> This works great but I cannot "deploy" my GoLang app to Google App
>>>> Engine so this is not possible.
>>>>
>>>> ---
>>>>
>>>> *This does NOT work. It follows the tutorial. I tried 4 different
>>>> variations.*
>>>>
>>>> connectionName = "CONNECTION_NAME"
>>>> db, err := sql.Open("postgres", fmt.Sprintf("%s:%s@cloudsql(%s)",
>>>> user, password, connectionName))
>>>> db, err := sql.Open("postgres", fmt.Sprintf("%s:%s@cloudsql(%s)/DB_NAME",
>>>> user, password, connectionName))
>>>> db, err := sql.Open("postgres", 
>>>> fmt.Sprintf("postgres://%s:%s@cloudsql(%s)",
>>>> user, password, connectionName))
>>>> db, err := sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@
>>>> cloudsql(%s)/DB_NAME", user, password, connectionName))
>>>>
>>>> All four of these variations do not work. And I do not know why. I
>>>> could really use some help understanding why. The only difference between
>>>> this and the tutorial is that I'm using "postgres", not "mysql".
>>>> ```
>>>>
>>>> Thank you so kindly in advance.
>>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Google App Engine" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at https://groups.google.com/group/google-appengine.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/google-appengine/2cc425fa-b87c-409b-b423-a7b8a3bc1065%
>>> 40googlegroups.com
>>> <https://groups.google.com/d/msgid/google-appengine/2cc425fa-b87c-409b-b423-a7b8a3bc1065%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>>
>> Josh Moore |  Cloud Solutions Engineer |  [email protected] |
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/google-appengine.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/google-appengine/e8bd03ea-06f1-49a3-ab5c-
> c6c60b235001%40googlegroups.com
> <https://groups.google.com/d/msgid/google-appengine/e8bd03ea-06f1-49a3-ab5c-c6c60b235001%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 

Josh Moore |  Cloud Solutions Engineer |  [email protected] |

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/CAOvpJmVvEOa%3DW8dh-k6Q5e58x%3DnHPn3mt_sBBJOioBxw4N18eQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to