I am trying to use Google Cloud Storage from GAE and all works fine when deployed. I am however unable to get the storage to work on the development server that runs on Google Cloud Shell.
I am using the cloudstorage API and my understanding it that dev_appserver should access same buckets as the deployed application. For me working with local data would be fine as well.
The development server is invoked by dev_appserver.py .
I have played around with the non-documented default_gcs_bucket_name flag but no luck.
I have set he cloud shell to work with the correct project using gcloud init. I have also tried to use the new google.cloud.storage API without luck.
The same error as referenced below is triggered if I run the sample provided here: App Engine and Google Cloud Storage Sample.
Anyone?
Edit: I get the same error regardless of whether I supply a valid or an invalid bucket name.
app.yaml
runtime: python27
api_version: 1
threadsafe: true
builtins:
- remote_api: on
handlers:
- url: /.*
script: main.app
main.py
import logging
import cloudstorage as gcs
import webapp2
from google.appengine.api import app_identity
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
bucket_name = "xxxx-xxxxxx.appspot.com"
stats = gcs.listbucket('/'+bucket_name)
for stat in stats:
self.response.write(repr(stat) + '')
app = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)
Log
INFO 2017-06-07 20:36:42,068 devappserver2.py:116] Skipping SDK update check.
INFO 2017-06-07 20:36:42,105 api_server.py:297] Starting API server at: http://0.0.0.0:38829
INFO 2017-06-07 20:36:42,110 dispatcher.py:209] Starting module "default" running at: http://0.0.0.0:8080
INFO 2017-06-07 20:36:42,111 admin_server.py:116] Starting admin server at: http://0.0.0.0:8000
ERROR 2017-06-07 20:36:54,836 api_server.py:374] Exception while handling service_name: "app_identity_service"
method: "GetAccessToken"
request: "\n7https://www.googleapis.com/auth/devstorage.full_control"
request_id: "QBrGUwjoJT"
Traceback (most recent call last):
File "/google/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/api_server.py", line 349, in _handle_POST
api_response = _execute_request(request).Encode()
File "/google/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/api_server.py", line 225, in _execute_request
make_request()
File "/google/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/api_server.py", line 220, in make_request
request_id)
File "/google/google-cloud-sdk/platform/google_appengine/google/appengine/api/apiproxy_stub.py", line 131, in MakeSyncCall
method(request, response)
File "/google/google-cloud-sdk/platform/google_appengine/google/appengine/api/app_identity/app_identity_defaultcredentialsbased_stub.py", line 195, in _Dynamic_GetAccessToken
'expires': now + token.expires_in,
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
WARNING 2017-06-07 20:36:54,838 tasklets.py:468] suspended generator _make_token_async(rest_api.py:55) raised RuntimeError(TypeError("unsupported operand type(s) for +: 'int' and 'NoneType'",))
WARNING 2017-06-07 20:36:54,839 tasklets.py:468] suspended generator get_token_async(rest_api.py:224) raised RuntimeError(TypeError("unsupported operand type(s) for +: 'int' and 'NoneType'",))
WARNING 2017-06-07 20:36:54,839 tasklets.py:468] suspended generator urlfetch_async(rest_api.py:259) raised RuntimeError(TypeError("unsupported operand type(s) for +: 'int' and 'NoneType'",))
WARNING 2017-06-07 20:36:54,839 tasklets.py:468] suspended generator run(api_utils.py:164) raised RuntimeError(TypeError("unsupported operand type(s) for +: 'int' and 'NoneType'",))
WARNING 2017-06-07 20:36:54,839 tasklets.py:468] suspended generator do_request_async(rest_api.py:198) raised RuntimeError(TypeError("unsupported operand type(s) for +: 'int' and 'NoneType'",))
WARNING 2017-06-07 20:36:54,839 tasklets.py:468] suspended generator do_request_async(storage_api.py:137) raised RuntimeError(TypeError("unsupported operand type(s) for +: 'int' and 'NoneType'",))
Follow the instructions available in How the Application Default Credentials work (condition 1.)
It involves setting GOOGLE_APPLICATION_CREDENTIALS env variable to point to a valid json credentials file.
For these tests, I just created a new one selecting App Engine default service account:
...and it worked beautifully.
According to How the Application Default Credentials work running gcloud auth application-default login (condition 2.) should also solve the issue but I have not been able to make it work on Cloud Shell, it fails with the same "access token related" error :-(
dev_appserver.py uses configurations set in your local environment. Make sure the configs set on gcloud init is also correct for deploying to production.
To set Cloud Storage account permissions, go to Cloud Console then:
Storage > Browser > Right Button of your bucket > Edit bucket permissions
Add your account as Storage Admin or the likes.
Make sure you're logged in and have authorized the default service credentials.
% gcloud auth login
% gcloud auth application-default login
Related
I am unable to deploy a Dockerized application to App Engine Flexible Environment (AEF) in a Google Cloud Platform (GCP) project with a provisioned Shared Virtual Private Cloud (XPN).
In other words, my application with the following app.yaml:
automatic_scaling:
max_num_instances: 1
min_num_instances: 1
env: flex
network:
instance_tag: incorrect-target-tag
name: projects/$GCP_PROJECT_ID/global/networks/$XPN_NETWORK_NAME
service: $AEF_APPLICATION_NAME
and a confirmed Docker image name and tag in Google Container Registry (GCR):
gcloud container images list-tags \
us.gcr.io/$GCP_PROJECT_NAME/$AEF_APPLICATION_NAME \
--flatten=tags \
--format='value(format("us.gcr.io/$GCP_PROJECT_NAME/$AEF_APPLICATION_NAME:{0}", tags))' \
--project=$GCP_PROJECT_NAME
#=>
. . .
us.gcr.io/$GCP_PROJECT_NAME/$AEF_APPLICATION_NAME:$DOCKER_IMAGE_TAG
. . .
is unable to be deployed to AEF:
yes | gcloud app deploy \
--appyaml=./app.yaml \
--image-url=us.gcr.io/$GCP_PROJECT_NAME/$AEF_APPLICATION_NAME:$DOCKER_IMAGE_TAG
#=>
Services to deploy:
descriptor: [/. . ./app.yaml]
source: [/. . ./$AEF_APPLICATION_NAME]
target project: [$GCP_PROJECT_NAME]
target service: [$AEF_APPLICATION_NAME]
target version: [$AEF_APPLICATION_VERSION]
target url: [. . .]
target service account: [App Engine default service account]
Do you want to continue (Y/n)?
Beginning deployment of service [$AEF_APPLICATION_NAME]...
WARNING: Deployment of service [$AEF_APPLICATION_NAME] will ignore the skip_files field in the configuration file, because the image has already been built.
Updating service [$AEF_APPLICATION_NAME] (this may take several minutes)...
.............................................................failed.
ERROR: (gcloud.app.deploy) Error Response: [13] Flex operation projects/$GCP_PROJECT_NAME/regions/$AEF_APPLICATION_REGION/operations/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx error [INTERNAL]: An internal error occurred while processing task /app-engine-flex/insert_flex_deployment/flex_create_resources>1970-01-01T00:00:00.001Z000001.jc.2: <eye3 title='FAILED_PRECONDITION'/> generic::FAILED_PRECONDITION: Validation error: The App Engine flexible Environment Service Agent is unable to find a suitable Flex Firewall Rule in network '$XPN_NETWORK_NAME' in project '$GCP_PROJECT_ID'. Have the Shared VPC Admin create a Flex Firewall Rule as described in https://cloud.google.com/appengine/docs/flexible/python/using-shared-vpc
with the following Virtual Private Cloud (VPC) firewall rule supporting AEF communication through the XPN:
cloud compute firewall-rules list \
--filter="allowed[].ports=(8443) AND allowed[].ports=(10402)" \
--project=$GCP_PROJECT_NAME
#=>
NAME NETWORK DIRECTION PRIORITY ALLOW DENY DISABLED
aef-instance $XPN_NETWORK_NAME INGRESS 1000 tcp:8443,tcp:10402 False
To show all fields of the firewall, please show in JSON format: --format=json
To show all fields in table format, please see the examples in --help.
gcloud compute firewall-rules describe \
aef-instance \
--format=yaml \
--project=$GCP_PROJECT_NAME
#=>
allowed:
- IPProtocol: tcp
ports:
- '8443'
- '10402'
creationTimestamp: '1970-01-01T00:00:00.000-01:00'
description: allows traffic between aef and xpn
direction: INGRESS
disabled: false
id: 'xxxxxxxxxxxxxxxxxxx'
kind: compute#firewall
logConfig:
enable: false
name: aef-instance
network: https://www.googleapis.com/compute/v1/projects/$GCP_PROJECT_NAME/global/networks/$XPN_NETWORK_NAME
priority: 1000
selfLink: https://www.googleapis.com/compute/v1/projects/$GCP_PROJECT_NAME/global/firewalls/aef-instance
sourceRanges:
- 35.191.0.0/16
- 130.211.0.0/22
targetTags:
- incorrect-target-tag
Note: this rule is required for using any AEF application with the XPN, described here.
Following the guide to linking AEF and the XPN here, the target tag for VPC Firewall rule aef-instance MUST be aef-instance. Update VPC Firewall rule aef-instance with the correct target tag:
gcloud compute firewall-rules update \
aef-instance \
--project=$GCP_PROJECT_NAME \
--target-tags=aef-instance
#=>
Updated [https://www.googleapis.com/compute/v1/projects/$GCP_PROJECT_NAME/global/firewalls/aef-instance].
and you will be able to redeploy to AEF without that validation error.
Note: changing the target tag in the app.yaml isn't necessary: the AEF application will be able to communicate over a provisioned XPN as long as there is a firewall rule that meets this criteria exactly, regardless of tags specified in the app.yaml.
I am getting the error
Error Response: [4] App Engine Flexible timed out while configuring
resources, internal operation
while deploying .NetCore application to my App Engine. App Engine is currently in Asia South. I also created another project with App Engine at US East. On that I am getting error
ERROR: (gcloud.app.deploy) INTERNAL: Internal error encountered.
while deploying. Tried to deploy the Hello world application specified in GCP docs. It is also getting same issues while deploying. Am I missing something. I have updated BACKEND_SEVICES quota. After that only I am getting this issue. Also able to see versions as serving. But no Instances are active. I am not able to activate any other versions. It is also showing as Internal error.
This is my app.YAML
runtime: aspnetcore
env: flex
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 10
beta_settings:
cloud_sql_instances: "#########:#####-api-system=tcp:3306"
It was working fine till yesterday. I am getting this issue from today onwards.
Attaching Verbosity Logs
Updating service [default] (this may take several minutes)...|DEBUG: Operation [apps/**projectid**/operations/c46a17bd-d4a8-468f-b40b-47a7fdd03067] not complete. Waiting to retry.
Updating service [default] (this may take several minutes)...|DEBUG: Operation [apps/**projectid**/operations/c46a17bd-d4a8-468f-b40b-47a7fdd03067] not complete. Waiting to retry.
Updating service [default] (this may take several minutes)...\DEBUG: Operation [apps/**projectid**/operations/c46a17bd-d4a8-468f-b40b-47a7fdd03067] not complete. Waiting to retry.
Updating service [default] (this may take several minutes)...\DEBUG: Operation [apps/**projectid**/operations/c46a17bd-d4a8-468f-b40b-47a7fdd03067] not complete. Waiting to retry.
Updating service [default] (this may take several minutes)...-DEBUG: Operation [apps/**projectid**/operations/c46a17bd-d4a8-468f-b40b-47a7fdd03067] complete. Result: {
"done": true,
"error": {
"code": 4,
"message": "App Engine Flexible timed out while configuring resources, internal operation projects/**projectid**/regions/asia-south1/operations/700238de-3add-4281-80f8-6dc66948a715"
},
"metadata": {
"#type": "type.googleapis.com/google.appengine.v1.OperationMetadataV1",
"createVersionMetadata": {
"cloudBuildId": "38b57f34-3b23-4484-9d69-0c581995947f"
},
"endTime": "2020-04-23T23:40:50.335Z",
"insertTime": "2020-04-23T23:29:10.164Z",
"method": "google.appengine.v1.Versions.CreateVersion",
"target": "apps/**projectid**/services/default/versions/20200424t045856",
"user": "eltuniverse#gmail.com"
},
"name": "apps/**projectid**/operations/c46a17bd-d4a8-468f-b40b-47a7fdd03067"
}
Updating service [default] (this may take several minutes)...failed.
DEBUG: (gcloud.app.deploy) Error Response: [4] App Engine Flexible timed out while configuring resources, internal operation projects/**projectid**/regions/asia-south1/operations/700238de-3add-4281-80f8-6dc66948a715
Traceback (most recent call last):
File "C:\Google\CloudSDK\google-cloud-sdk\lib\googlecloudsdk\calliope\cli.py", line 983, in Execute
resources = calliope_command.Run(cli=self, args=args)
File "C:\Google\CloudSDK\google-cloud-sdk\lib\googlecloudsdk\calliope\backend.py", line 807, in Run
resources = command_instance.Run(args)
File "C:\Google\CloudSDK\google-cloud-sdk\lib\surface\app\deploy.py", line 111, in Run
return deploy_util.RunDeploy(
File "C:\Google\CloudSDK\google-cloud-sdk\lib\googlecloudsdk\command_lib\app\deploy_util.py", line 634, in RunDeploy
deployer.Deploy(
File "C:\Google\CloudSDK\google-cloud-sdk\lib\googlecloudsdk\command_lib\app\deploy_util.py", line 431, in Deploy
self.api_client.DeployService(new_version.service, new_version.id,
File "C:\Google\CloudSDK\google-cloud-sdk\lib\googlecloudsdk\api_lib\app\appengine_api_client.py", line 204, in DeployService
return operations_util.WaitForOperation(
File "C:\Google\CloudSDK\google-cloud-sdk\lib\googlecloudsdk\api_lib\app\operations_util.py", line 307, in WaitForOperation
completed_operation = waiter.WaitFor(
File "C:\Google\CloudSDK\google-cloud-sdk\lib\googlecloudsdk\api_lib\util\waiter.py", line 261, in WaitFor
operation = PollUntilDone(
File "C:\Google\CloudSDK\google-cloud-sdk\lib\googlecloudsdk\api_lib\util\waiter.py", line 322, in PollUntilDone
operation = retryer.RetryOnResult(
File "C:\Google\CloudSDK\google-cloud-sdk\lib\googlecloudsdk\core\util\retry.py", line 229, in RetryOnResult
if not should_retry(result, state):
File "C:\Google\CloudSDK\google-cloud-sdk\lib\googlecloudsdk\api_lib\util\waiter.py", line 320, in _IsNotDone
return not poller.IsDone(operation)
File "C:\Google\CloudSDK\google-cloud-sdk\lib\googlecloudsdk\api_lib\app\operations_util.py", line 182, in IsDone
raise OperationError(requests.ExtractErrorMessage(
googlecloudsdk.api_lib.app.operations_util.OperationError: Error Response: [4] App Engine Flexible timed out while configuring resources, internal operation projects/**projectid**/regions/asia-south1/operations/700238de-3add-4281-80f8-6dc66948a715
ERROR: (gcloud.app.deploy) Error Response: [4] App Engine Flexible timed out while configuring resources, internal operation projects/**projectid**/regions/asia-south1/operations/700238de-3add-4281-80f8-6dc66948a715
App.yaml
runtime: aspnetcore
env: flex
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 10
beta_settings:
cloud_sql_instances: "***projectid***:asia-south1:***dbname***=tcp:3306"
Thanks.
It is recommended to get more detail in this cases. You can deploy with: gcloud app deploy --verbosity=debug, just to see if you can retrieve more information about this.
It seems this could be due to some reasons. I recommend to check:
In some cases is useful to run this command $ gcloud config set app/trigger_build_server_side false in order to force that the building will be managed on the client side rather than the server side (which could be changed in somehow), before deploying. Try this command and then deploy again.
Possible changes in the configuration of your app. Take a look into your app.yaml, check for different values. Comparing the version of Apr 22 and that the one of today. Is it possible for you to deploy the version of yesterday?
The quotas in your project associated to App Engine and Compute Engine. Remember that, in the end, App Engine Flex runs in VMs. Here is a similar issue, related with the quota: In-use IP addresses. If you see any quota exhausted, you can request a Quota increase.
In some cases, this can also be related to an internal issue, in such case you should create a case in GCP. (lets keep this as final option)
Also, could you pleas share relevant detailed logs about this? Please, be sure of not sharing any sensitive information
Please let me know your findings with this. Also it would be great if you can share the app.yaml of both versions (working and not) in case the aforementioned does not work.
I am running into this error while deploying my app to google app-engine.
Error:
Error 404: --- begin server output ---
This application does not exist (project_id=u'homework-153002'). To create an App Engine application in this project, run "gcloud beta app create" in your console.
--- end server output ---
When I try to create the app using the above command this is what I see:
ERROR: (gcloud.beta.app.create) You do not have permission to access app [homework] (or it may not exist): Operation not allowed
I have created a project in google developers api website with project_name of "homework" and random id. Here is the url for that:
https://console.developers.google.com/apis/library?project=homework-153002
Any pointers on what I might be doing wrong here?
This is my yaml file:
application: homework-153002
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: .*
script: main.app
libraries:
- name: webapp2
version: "2.5.2"
Your app URL indicates your app ID is homework-153002, but the
error message indicates you're connecting to an ap called homework - likely not your own, hence the permission issue.
Simply correcting the app ID in your deployment command and/or your app.yaml file should suffice.
As your comment indicates, for your case (gcloud deployment) the solution was:
gcloud config set project homework-153002
gcloud beta app create
appcfg.py update homework/
While trying to appcfg.py update myProject, my endpoints failed to update. Here is part of the trace:
09:36 PM Failed to update Endpoints configuration. The app returned an error when the Google Cloud Endpoints server attempted to communicate with it.
09:36 PM See the deployment troubleshooting documentation for more information: https://developers.google.com/appengine/docs/python/endpoints/test_deploy#troubleshooting_a_deployment_failure
09:36 PM Ignoring Endpoints failure and proceeding with update.
I tried to check the logs at http://localhost:8080/_ah/spi/BackendService.getApiConfigs, but terminal produces the following error:
#endpoints.api(name='EventsAPI', version='v1')
AttributeError: 'module' object has no attribute 'api'
INFO 2016-03-18 02:01:37,742 module.py:787] default: "GET /_ah/spi/BackendService.getApiConfigs HTTP/1.1" 500 -
Here is my code:
import endpoints
from protorpc import messages
from protorpc import message_types
from protorpc import remote
package = 'Events'
#endpoints.api(name='EventsAPI', version='v1')
class EventsAPI(remote.Service):
# insert lots of endpoint methods
APPLICATION = endpoints.api_server([EventsAPI])
I am following this tutorial. Where did I go wrong?
There is a problem with the endpoints' name. The name EventsAPI is invalid; changing it to eventsapi fixed this issue.
For reference, as outlined in the endpoint definitions.
The name value: Must begin with lowercase.
I upload the Google App Engine application which is at the url developers.google.com/appengine/docs/python/memcache/usingmemcache#Memcache
When I run the application on Google App Engine Launcher, it runs but the website shows:
(First error is there us no Python "PIL" module but I am not using image. Could you please suggest what is causing the error?
*** Running dev_appserver with the following flags:
--skip_sdk_update_check=yes --port=13080 --admin_port=8005
Python command: /usr/bin/python2.7
INFO 2014-01-17 20:43:22,217 devappserver2.py:660] Skipping SDK update check.
WARNING 2014-01-17 20:43:22,222 api_server.py:331] Could not initialize images API; you are likely missing the Python "PIL" module.
INFO 2014-01-17 20:43:22,226 api_server.py:138] Starting API server at: localhost:55385
INFO 2014-01-17 20:43:22,230 dispatcher.py:171] Starting module "default" running at: localhost:13080
INFO 2014-01-17 20:43:22,238 admin_server.py:117] Starting admin server at: localhost:8005
ERROR 2014-01-17 20:43:24,601 wsgi.py:262]
Traceback (most recent call last):
File "/Users/Desktop/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 239, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/Users/Desktop/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 301, in _LoadHandler
raise err
ImportError: <module 'guestbookw2' from '/Users/guestbookw2/guestbookw2.pyc'> has no attribute application
INFO 2014-01-17 20:43:24,607 module.py:617] default: "GET / HTTP/1.1" 500 -
ERROR 2014-01-17 20:43:24,727 wsgi.py:262]
Traceback (most recent call last):
File "/Users/Desktop/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 239, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/Users/Desktop/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 301, in _LoadHandler
raise err
ImportError: <module 'guestbookw12' from '/Users/guestbookw2/guestbookw2.pyc'> has no attribute application
INFO 2014-01-17 20:43:24,732 module.py:617] default: "GET /favicon.ico HTTP/1.1" 500 -
Make sure that you have the following files in the path that you are uploading your application from:
index.yaml (auto-generated; you don't need to add or change anything in here at this point).
favicon.ico (in the correct format; should be 16x16 or 32x32 pixels if I remember correctly).
main.py (mapping all the paths in your web-site; example given below):
from webapp2 import WSGIApplication
from Server import MainRequestHandler
from Server import SomeRequestHandler
from Server import OtherRequestHandler
app = WSGIApplication([
('/' ,MainRequestHandler),
('/abc' ,SomeRequestHandler),
('/def' ,SomeRequestHandler),
('/xyz' ,OtherRequestHandler),
])
app.yaml (with the following contents; using <...> where you need to set a value):
application: <the app-id you chose when use signed in for GAE>
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: .*
script: main.app
libraries:
- name: webapp2
version: "2.5.1" // you might need to change this as well
Note:
if you wish to avoid handling 'favicon.ico' request, then you must remove the reference in file 'app.yaml'.
Supplemental:
You will need to implement all the request handlers imported in 'main.py'.
In the example above, 'main.py' expects to find them in a Python module named 'Server'.
Each request handler must inherit class RequestHandler, imported from webapp2.
Supplemental #2:
In order to solve the 'PIL' issue (had a similar problem if memory serves correctly), simply install it.
From a Windows command line, enter: pip install pil.