{"id":597,"date":"2020-03-17T21:52:37","date_gmt":"2020-03-17T12:52:37","guid":{"rendered":"https:\/\/www.typea.info\/blog\/?p=597"},"modified":"2020-03-17T21:52:37","modified_gmt":"2020-03-17T12:52:37","slug":"google-cloud-functinos","status":"publish","type":"post","link":"https:\/\/www.typea.info\/blog\/index.php\/2020\/03\/17\/google-cloud-functinos\/","title":{"rendered":"Google Cloud Functinos \u3092\u8a66\u3057\u3066\u307f\u308b"},"content":{"rendered":"<p><a href=\"https:\/\/www.amazon.co.jp\/Google-Cloud-Platform-%E5%AE%9F%E8%B7%B5Web%E3%82%A2%E3%83%97%E3%83%AA%E9%96%8B%E7%99%BA-%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AA%E3%83%BC%E3%81%A7%E5%AD%A6%E3%81%B6Google-Engine\/dp\/4798059552\/ref=as_li_ss_il?__mk_ja_JP=%E3%82%AB%E3%82%BF%E3%82%AB%E3%83%8A&amp;crid=3K7CRWGEY4B9I&amp;keywords=google+cloud+platform&amp;qid=1584449482&amp;sprefix=Google+Cloud+,aps,273&amp;sr=8-4&amp;linkCode=li2&amp;tag=typea09-22&amp;linkId=c7d00efc41aef753a84f73ed972a6ee4\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"\/\/ws-fe.amazon-adsystem.com\/widgets\/q?_encoding=UTF8&amp;ASIN=4798059552&amp;Format=_SL160_&amp;ID=AsinImage&amp;MarketPlace=JP&amp;ServiceVersion=20070822&amp;WS=1&amp;tag=typea09-22\" border=\"0\"><\/a><img loading=\"lazy\" decoding=\"async\" width=\"1\" height=\"1\" style=\"margin: 0px !important; border: currentcolor !important; border-image: none !important;\" alt=\"\" src=\"https:\/\/ir-jp.amazon-adsystem.com\/e\/ir?t=typea09-22&amp;l=li2&amp;o=9&amp;a=4798059552\" border=\"0\"><\/p>\n<p>\u307c\u3061\u307c\u3061\u3068\u3001<a href=\"https:\/\/www.typea.info\/blog\/index.php\/2019\/04\/30\/google_app_enginejavaspring_bootvuetifygoogle_cloud_vision_apiocr\/\">GCP\u3092\u4f7f\u3063\u3066\u74b0\u5883\u3092\u4f5c\u308d\u3046\u3068\u601d\u3063\u3066\u3044\u308b<\/a>\u306e\u3060\u3051\u308c\u3069\u3001<\/p>\n<p>\u3044\u304b\u3093\u305b\u3093\u4ed5\u4e8b\u3067\u306f\u306a\u3044\u306e\u3067\u307e\u3068\u307e\u3063\u305f\u6642\u9593\u304c\u53d6\u308c\u306a\u3044\u3002<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/index.php\/category\/google-cloud-platform\/\">\u8a66\u884c\u932f\u8aa4\u3057\u3066\u304d\u305f\u304c<\/a>\u3001\u4f55\u3068\u304b\u5f62\u306b\u3059\u308b\u305f\u3081\u306b\u306f\u3001\u3082\u3063\u3068\u958b\u767a\u52b9\u7387\u3092\u3042\u3052\u308b\u5fc5\u8981\u304c\u3042\u308b<\/p>\n<p><\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001Firebase\u3084Google Cloud API\u3068\u89aa\u548c\u6027\u304c\u9ad8\u305d\u3046\u306a\u3001Google Cloud Functions\u3092\u8a66\u3059\u3002<\/p>\n<p>\u3056\u3063\u3068\u6982\u8981\u3092\u8aad\u3093\u3067\u3001\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3092\u52d5\u304b\u3057\u3066\u611f\u899a\u3092\u3064\u304b\u307f\u305f\u3044\u3002<\/p>\n<p><\/p>\n<p><a href=\"https:\/\/cloud.google.com\/functions?hl=ja\">Cloud Functions<\/a><\/p>\n<p><\/p>\n<p>HTTP\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb<\/p>\n<p><a href=\"https:\/\/cloud.google.com\/functions\/docs\/tutorials\/http?hl=ja\">https:\/\/cloud.google.com\/functions\/docs\/tutorials\/http?hl=ja<\/a><\/p>\n<p><\/p>\n<h2>1.\u6e96\u5099<\/h2>\n<ul>\n<li>GCP\u30d7\u30ed\u30b8\u30a7\u30af\u30c8 \u8ab2\u91d1\u6709\u52b9\u306b\u3059\u308b<\/li>\n<li>SDK\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u6700\u65b0\u306b<\/li>\n<\/ul>\n<p>&gt; gcloud components update<\/p>\n<p><\/p>\n<h2>2.\u958b\u767a\u74b0\u5883\u3092\u6e96\u5099<\/h2>\n<h3>2.1 Node.js<\/h3>\n<p>Node.js \u3068 Python \u3068 Go\u304c\u9078\u629e\u3067\u304d\u308b\u304c\u3001Node.js\u3092\u9078\u629e\u3059\u308b<\/p>\n<p><a href=\"https:\/\/cloud.google.com\/nodejs\/docs\/setup?hl=ja\">https:\/\/cloud.google.com\/nodejs\/docs\/setup?hl=ja<\/a><\/p>\n<h3>2.2 NVM<\/h3>\n<p>Windows\u3067\u306f\u3001Node.js\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u7ba1\u7406\u30c4\u30fc\u30ebNVM\u304c\u5229\u7528\u3067\u304d\u306a\u3044\u306e\u3067\u3001\u4ee5\u4e0b\u3092\u5229\u7528\u3059\u308b<\/p>\n<p>nvm-windows <a href=\"https:\/\/blog.clock-up.jp\/entry\/2018\/02\/10\/nodejs-manager-on-windows\">https:\/\/blog.clock-up.jp\/entry\/2018\/02\/10\/nodejs-manager-on-windows<\/a><\/p>\n<p>\u6e96\u5099\u3068\u3057\u3066\u3001\u4ee5\u524dNVM\u3092\u5229\u7528\u305b\u305a\u306b\u5358\u72ec\u3067Node.js\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3044\u305f\u5834\u5408\u3001\u65e2\u5b58Node.js\u306e\u30a2\u30f3\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3068npm\u30c7\u30a3\u30ec\u30af\u30c8\u306e\u524a\u9664\u3092\u884c\u3046\u3002<\/p>\n<p>npm\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306f\u4ee5\u4e0b\u306b\u3042\u308b\u3002<\/p>\n<p>C:\\Users\\{User}\\AppData\\Roaming\\npm<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/03\/nvm_install.png\"><img loading=\"lazy\" decoding=\"async\" width=\"568\" height=\"178\" title=\"nvm_install\" style=\"display: inline; background-image: none;\" alt=\"nvm_install\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/03\/nvm_install_thumb.png\" border=\"0\"><\/a><\/p>\n<p><\/p>\n<h4>Download \u2013 install (nvm-setup.zip) \u30a4\u30f3\u30b9\u30c8\u30fc\u30e9\u30fc\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u89e3\u51cd\u3001\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3002<\/h4>\n<p><a href=\"https:\/\/github.com\/coreybutler\/nvm-windows\/releases\">https:\/\/github.com\/coreybutler\/nvm-windows\/releases<\/a><\/p>\n<p><\/p>\n<p>nvm\u30b3\u30de\u30f3\u30c9\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308b\u306e\u3067\u3001\u6700\u65b0\u306eNode\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u30a2\u30af\u30c6\u30a3\u30d6\u306b\u3059\u308b<\/p>\n<p><pre class=\"prettyprint\">&gt; nvm install latest\n&gt; nvm list\n    13.11.0\n&gt; nvm use 13.11.0\nNow using node v13.11.0 (64-bit)\n<\/pre>\n<p><\/p>\n<p>\u30e6\u30fc\u30b6\u30fc\u540d\u306b\u7a7a\u767d\u304c\u542b\u307e\u308c\u3066\u3044\u305f\u305f\u3081\u3001\u4ee5\u4e0b\u306e\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u305f\u3002\u30a4\u30f3\u30b9\u30c8\u30fc\u30e9\u30fc\u3067\u3001\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u5148\u306b\u30d6\u30e9\u30f3\u30af\u3092\u542b\u307e\u306a\u3044\u30d1\u30b9\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u56de\u907f<\/p>\n<p><\/p>\n<p>\u30a8\u30e9\u30fc\u5185\u5bb9<\/p>\n<p><pre class=\"prettyprint\">C:\\Users\\Hiroto Yagi&gt;nvm use 13.11.0\nexit status 1: 'C:\\Users\\Hiroto' is not recognized as an internal or external command,\noperable program or batch file.<\/pre>\n<p><\/p>\n<p>NG\u306a\u30d1\u30b9\u306e\u4f8b<\/p>\n<p>C:\\Users\\Hiroto Yagi\\AppData\\Roaming\\nvm<\/p>\n<p><\/p>\n<p>\u30a4\u30f3\u30b9\u30c8\u30fc\u30e9\u3067\u7a7a\u767d\u3092\u542b\u307e\u306a\u3044\u30d1\u30b9\u3092\u6307\u5b9a\u3059\u308b<\/p>\n<p><p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/03\/nvm_install2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"433\" height=\"356\" title=\"nvm_install2\" style=\"display: inline; background-image: none;\" alt=\"nvm_install2\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/03\/nvm_install2_thumb.png\" border=\"0\"><\/a><\/p>\n<h2><\/h2>\n<h2>3.\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u6e96\u5099<\/h2>\n<p><pre class=\"prettyprint\">\u4ee5\u4e0b\u304b\u3089\u30b5\u30f3\u30d7\u30eb\u3092\u30af\u30ed\u30fc\u30f3\u3059\u308b<\/pre>\n<pre class=\"prettyprint\">git clone <a href=\"https:\/\/github.com\/GoogleCloudPlatform\/nodejs-docs-samples.git\">https:\/\/github.com\/GoogleCloudPlatform\/nodejs-docs-samples.git<\/a><\/pre>\n<p><\/p>\n<p>\u4eca\u56de\u306e\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u30d5\u30a9\u30eb\u30c0\u3078<\/p>\n<pre>cd nodejs-docs-samples\/functions\/helloworld\/<\/pre>\n<pre><br><\/pre>\n<p><pre class=\"prettyprint\">\/\/ [START functions_helloworld_get]\n\/**\n * HTTP Cloud Function.\n * This function is exported by index.js, and is executed when\n * you make an HTTP request to the deployed function's endpoint.\n *\n * @param {Object} req Cloud Function request context.\n *                     More info: https:\/\/expressjs.com\/en\/api.html#req\n * @param {Object} res Cloud Function response context.\n *                     More info: https:\/\/expressjs.com\/en\/api.html#res\n *\/\nexports.helloGET = (req, res) =&gt; {\n  res.send('Hello World!');\n};\n\/\/ [END functions_helloworld_get]\n<\/pre>\n<p><\/p>\n<p><\/p>\n<h2>4.\u95a2\u6570\u306e\u30c7\u30d7\u30ed\u30a4<\/h2>\n<p>\u95a2\u6570\u3092\u30c7\u30d7\u30ed\u30a4\u3059\u308b\u3002<\/p>\n<ul>\n<li>&#8211;runtime :\u512a\u5148\u3059\u308b Node.js \u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u6307\u5b9a<\/li>\n<li>&#8211;allow-unauthenticated :\u8a8d\u8a3c\u306a\u3057\u3067\u95a2\u6570\u306b\u30a2\u30af\u30bb\u30b9<\/li>\n<\/ul>\n<p><\/p>\n<p><pre class=\"prettyprint\"> &gt; gcloud functions deploy helloGET --runtime nodejs8 --trigger-http --allow-unauthenticated      \n API [cloudfunctions.googleapis.com] not enabled on project\n [426030064127]. Would you like to enable and retry (this will take a\n few minutes)? (y\/N)?  y\n \n Enabling service [cloudfunctions.googleapis.com] on project [426030064127]...\n Operation \"operations\/acf.1a3f3574-f2ee-47e6-aa8a-ae5c7c023bb8\" finished successfully.\n Deploying function (may take a while - up to 2 minutes)...WARNING: Setting IAM policy failed, try \"gcloud alpha functions add-iam-policy-binding helloGET --member=allUsers --role=roles\/cloudfunctions.invoker\"\n Deploying function (may take a while - up to 2 minutes)...done.\n availableMemoryMb: 256\n entryPoint: helloGET\n httpsTrigger:\n   url: https:\/\/us-central1-typea-gcp-api-trial.cloudfunctions.net\/helloGET\n ingressSettings: ALLOW_ALL\n labels:\n   deployment-tool: cli-gcloud\n name: projects\/typea-gcp-api-trial\/locations\/us-central1\/functions\/helloGET\n runtime: nodejs8\n serviceAccountEmail: typea-gcp-api-trial@appspot.gserviceaccount.com\n sourceUploadUrl: https:\/\/storage.googleapis.com\/gcf-upload-us-central1-4fc76f27-799e-40e6-ba7b-606e7e3f0e01\/fb7e562d-1c64-421c-8752-69e6d378959f.zip?GoogleAccessId=service-426030064127@gcf-admin-robot.iam.gserviceaccount.com&amp;Expires=1584448781&amp;Signature=qNToHvXwpCyMwnq3fLx%2FnZUggs4xm9Y8ZUv5QgjDUhVYoqqstSUEgD5sSKqmeXPwERls2z5sO3ydKdTJjjfen7AeLSuY%2BVZgdC4bbWIrUbosyoyBAi58a%2F%2BiDODYNT9jr8uUdmMZZCmaaoiu96Y3%2BtKcMWaNppT1KchXJL1EBG053GAtPwAqfVOy%2Ba3OVk51%2BXu4q4Upt3zlCiii0SRwi6z%2F5gVEc4hdCf0GcNk7txUWdOPrzvXz0JdIxcplcBp8r%2Fu%2FqJSgr6mL0tGi0UQdUYtsV7iqhSk%2FCtNtOJvwbN%2ByWTiSr2%2FN51pBVOuT2PB5MQavZrhLTq4j6HAvu6gD%2BA%3D%3D  \n status: ACTIVE\n timeout: 60s\n updateTime: '2020-03-17T12:10:56.296Z'\n versionId: '1'<\/pre>\n<pre class=\"prettyprint\"><br><\/pre>\n<h2>5.\u95a2\u6570\u306e\u5b9f\u884c<\/h2>\n<p>\u30c7\u30d7\u30ed\u30a4\u6642\u306b\u7d50\u679c\u3068\u3057\u3066\u8868\u793a\u3055\u308c\u308b\u3001URL\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3002<\/p>\n<p>url: <a href=\"https:\/\/us-central1-typea-gcp-api-trial.cloudfunctions.net\/helloGET\">https:\/\/us-central1-typea-gcp-api-trial.cloudfunctions.net\/helloGET<\/a><\/p>\n<p><\/p>\n<p>\u5b9f\u884c\u3055\u308c\u305f\uff01<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/03\/gcp_function.png\"><img loading=\"lazy\" decoding=\"async\" width=\"810\" height=\"249\" title=\"gcp_function\" style=\"display: inline; background-image: none;\" alt=\"gcp_function\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/03\/gcp_function_thumb.png\" border=\"0\"><\/a><\/p>\n<h3>5.1 \u95a2\u6570\u306e\u30ea\u30b9\u30c8<\/h3>\n<p><pre class=\"prettyprint\"> &gt; gcloud functions list\n NAME      STATUS  TRIGGER       REGION\n helloGET  ACTIVE  HTTP Trigger  us-central1<\/pre>\n<p><\/p>\n<h3>5.2 \u95a2\u6570\u306e\u524a\u9664<\/h3>\n<p>\u6700\u5f8c\u306b\u524a\u9664\u3057\u3068\u304f\u3002<\/p>\n<p><pre class=\"prettyprint\"> &gt; gcloud functions delete helloGET\n Resource [projects\/typea-gcp-api-trial\/locations\/us-central1\/functions\n \/helloGET] will be deleted.\n \n Do you want to continue (Y\/n)?  y\n \n Waiting for operation to finish...done.\n Deleted [projects\/typea-gcp-api-trial\/locations\/us-central1\/functions\/helloGET].<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u307c\u3061\u307c\u3061\u3068\u3001GCP\u3092\u4f7f\u3063\u3066\u74b0\u5883\u3092\u4f5c\u308d\u3046\u3068\u601d\u3063\u3066\u3044\u308b\u306e\u3060\u3051\u308c\u3069\u3001 \u3044\u304b\u3093\u305b\u3093\u4ed5\u4e8b\u3067\u306f\u306a\u3044\u306e\u3067\u307e\u3068\u307e\u3063\u305f\u6642\u9593\u304c\u53d6\u308c\u306a\u3044\u3002 \u8a66\u884c\u932f\u8aa4\u3057\u3066\u304d\u305f\u304c\u3001\u4f55\u3068\u304b\u5f62\u306b\u3059\u308b\u305f\u3081\u306b\u306f\u3001\u3082\u3063\u3068\u958b\u767a\u52b9\u7387\u3092\u3042\u3052\u308b\u5fc5\u8981\u304c\u3042\u308b \u3068\u3044\u3046\u3053\u3068\u3067\u3001Fireb [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"sns_share_botton_hide":"","vkExUnit_sns_title":"","_vk_print_noindex":"","sitemap_hide":"","_veu_custom_css":"","veu_display_promotion_alert":"","vkexunit_cta_each_option":"","footnotes":""},"categories":[112,100,98],"tags":[],"class_list":["post-597","post","type-post","status-publish","format-standard","hentry","category-google-cloud-functions","category-google-cloud-platform","category-node-js"],"veu_head_title_object":{"title":"","add_site_title":""},"_links":{"self":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/597","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=597"}],"version-history":[{"count":1,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/597\/revisions"}],"predecessor-version":[{"id":598,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/597\/revisions\/598"}],"wp:attachment":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=597"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=597"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=597"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}