質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Google Cloud Platform

Google Cloud Platformは、Google社がクラウド上で提供しているサービス郡の総称です。エンドユーザー向けサービスと同様のインフラストラクチャーで運営されており、Webサイト開発から複雑なアプリ開発まで対応可能です。

Google App Engine

Google App Engineは、Googleの管理するデータセンター上でウェブアプリケーションの開発が可能なクラウドコンピュータ技術です。Java、Python、Go用にSDKが用意されています。

Sinatra

Sinatraは、Rubyで作られた オープンソースのWebアプリケーションフレームワークです。

Q&A

解決済

1回答

674閲覧

Cloud Endpointsを使ったGAEから、別プロジェクトのCloudSQLに接続したい

kuetsuhara

総合スコア6

Google Cloud Platform

Google Cloud Platformは、Google社がクラウド上で提供しているサービス郡の総称です。エンドユーザー向けサービスと同様のインフラストラクチャーで運営されており、Webサイト開発から複雑なアプリ開発まで対応可能です。

Google App Engine

Google App Engineは、Googleの管理するデータセンター上でウェブアプリケーションの開発が可能なクラウドコンピュータ技術です。Java、Python、Go用にSDKが用意されています。

Sinatra

Sinatraは、Rubyで作られた オープンソースのWebアプリケーションフレームワークです。

0グッド

0クリップ

投稿2018/08/03 09:48

編集2018/08/03 09:58

前提・実現したいこと

現在、APIサーバーをGAEで立てようとしています。
このチュートリアル(https://cloud.google.com/endpoints/docs/openapi/get-started-app-engine?hl=ja)を
Ruby言語を選んで、参考にしながらとりあえず立てることができたのですが、
このチュートリアル(https://cloud.google.com/appengine/docs/flexible/ruby/using-cloud-sql#before_you_begin)をやっていて
DBに接続するところで詰まってしまいました。

cloud_sql_proxyを使ってローカルからDB接続することは成功したのですが、
gaeにdeployするとエラーでデプロイできなくなってしまったので、そのデプロイで出るエラーを解決したいです。

※DBはGCP内ではありますが別プロジェクトにあります

発生している問題・エラーメッセージ

209e729f8486: Layer already exists b31a4422279c: Pushed fe8739e9df49: Pushed 6fb446f7ac33: Pushed latest: digest: sha256:c899761948f5c9a3a3d1179dcf76bd1df44ad36934d8b109c6ce7c4f5f42914e size: 2206 DONE ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Updating service [default] (this may take several minutes)...failed. ERROR: (gcloud.beta.app.deploy) Error Response: [9] Application startup error: /app/vendor/bundle/ruby/2.3.0/gems/mysql2-0.5.2/lib/mysql2/client.rb:90:in `connect': Mysql2::Error::ConnectionError: Can't connect to local MySQL server through socket '/cloudsql/xxxxxx:asia-northeast1:xxxxxxxxx' (2) (Sequel::DatabaseConnectionError) from /app/vendor/bundle/ruby/2.3.0/gems/mysql2-0.5.2/lib/mysql2/client.rb:90:in `initialize' from /app/vendor/bundle/ruby/2.3.0/gems/sequel-5.11.0/lib/sequel/adapters/mysql2.rb:44:in `new' from /app/vendor/bundle/ruby/2.3.0/gems/sequel-5.11.0/lib/sequel/adapters/mysql2.rb:44:in `connect' from /app/vendor/bundle/ruby/2.3.0/gems/sequel-5.11.0/lib/sequel/connection_pool.rb:127:in `make_new' from /app/vendor/bundle/ruby/2.3.0/gems/sequel-5.11.0/lib/sequel/connection_pool/threaded.rb:206:in `assign_connection' from /app/vendor/bundle/ruby/2.3.0/gems/sequel-5.11.0/lib/sequel/connection_pool/threaded.rb:138:in `acquire' from /app/vendor/bundle/ruby/2.3.0/gems/sequel-5.11.0/lib/sequel/connection_pool/threaded.rb:90:in `hold' from /app/vendor/bundle/ruby/2.3.0/gems/sequel-5.11.0/lib/sequel/database/connecting.rb:253:in `synchronize' from /app/vendor/bundle/ruby/2.3.0/gems/sequel-5.11.0/lib/sequel/database/connecting.rb:279:in `test_connection' from /app/vendor/bundle/ruby/2.3.0/gems/sequel-5.11.0/lib/sequel/database/connecting.rb:58:in `connect' from /app/vendor/bundle/ruby/2.3.0/gems/sequel-5.11.0/lib/sequel/core.rb:116:in `connect' from /app/vendor/bundle/ruby/2.3.0/gems/sequel-5.11.0/lib/sequel/core.rb:394:in `adapter_method' from /app/vendor/bundle/ruby/2.3.0/gems/sequel-5.11.0/lib/sequel/core.rb:401:in `block (2 levels) in def_adapter_method' from app.rb:29:in `<main>'

該当のソースコード

Ruby

1require "base64" 2require "json" 3require "sinatra" 4require "sequel" 5require 'dotenv' 6 7Dotenv.load 8 9DB = Sequel.mysql2 user: ENV["MYSQL_USER"], 10 password: ENV["MYSQL_PASSWORD"], 11 database: ENV["MYSQL_DATABASE"], 12 socket: ENV["MYSQL_SOCKET_PATH"]

※MYSQL_SOCKET_PATHは /cloudsql/<インスタンス接続名>

試したこと

これから同プロジェクトにDBがあったらつながるのか?を試します。

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

どうやらIAMの設定がうまくいってなかった&CloudSQLAPIが有効になっていなかったのが問題だったようです。
凡ミスでした…。

投稿2018/08/03 10:41

kuetsuhara

総合スコア6

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問