Start/Stop Google app engine custom runtime instances - google-app-engine

I made a small web service using Node.js and PhantomJS, and deployed it to Google app engine using its flexible environments...
The problem is, the service is used only for half an hour each day, but the VM instances is running all time and I pay for that...
So I need to be automatically able to start the instance(s) before scheduled run time of my app, and then automatically stop them
I tried use Cron jobs to call start/stop via the API, as in here, but it failed..
Thanks for advance

We don't seem to currently expose the version stop method in the rest API:
https://cloud.google.com/appengine/docs/admin-api/
However - you can stop a version by running this command:
gcloud app versions list
gcloud app versions stop <version>
That will make sure the VMs get shut down. When you're ready to turn them back on...
gcloud app versions start <version>
Hope this helps!

Related

Don't wait for "Updating service..."

I'm using Bitbucket Pipelines to deploy my project to Google App Engine via gcloud app deploy which does a great job accomplishing what I want.
gcloud app deploy takes like 6-8 extra minutes for "Updating service..." which is the time taking for them to update their backend infrastructure primarily the Load Balancer.
This is not an issue by itself except that it eats up my monthly Build Time from Bitbucket.
I would rather have the pipeline return as soon it sent off the build commands, and I'll check them myself on Google Cloud Logs server.
The question is: do we have any flag for gcloud app deploy to tell him not to wait for the "Updating service..." ?
These are all the gcloud app deploy flags. There's no such flag.
To see if there's a possible 'hack' you could use, you could try manually deploying your app yourself using gcloud app deploy --log-http. The --log-http flag will produce an output of all http requests made during the deploy. You'll see the endpoints being called, the http method, the headers, payload and the duration for each call. Examining those (especially around the 'updating' bit) might show you something that could potentially be of help.

How to run App Engine Standard apps locally (for development/testing) in 2021 without `dev_appserver.py`?

There have been a lot of changes to App Engine Standard. Is it still possible to have a local instance of the app runnable with something similar to dev_appserver.py and to use the new cloud.google.com/... APIs?
Previously, you could emulate the Datastore locally for example.
For GAE first gen apps, I believe the best option is to stick with dev_appserver.py. I'm keeping my fingers crossed that Google doesn't break that anytime soon.
For GAE second gen apps, you need to run your app directly (e.g. for Flask, python main.py) and run the datastore emulator in a separate terminal window. Other Google APIs need to be mocked or you can create a test GAE project and use the test project credentials when running locally. For the test project, you may have to pay a bit, but costs should be low.

How to set up and build previous image working in GCP

I'm new to google cloud.
Our project has been deployed on google Cloud. We are using gcloud deploy commands to deploy any build and we are good with it.
My question is: what if my current build fails during production deployment and there's lots of users using the application.
So, how can I update the previous image/build immediately in GCP? I have tried it with pull docker and push it then submitting via "gcloud build submit" command... but it's not deploying actual specified docker image, it's deploying that folder where I'm running commands of "gcloud build submit"..
Please share your suggestions..
Your concern to not break all the users when you are deploying a broken version is legit, and you aren't alone!!
That's why a cool feature exist on App Engine (and also on Cloud Run): Traffic splitting.
To use it efficiently, you can deploy your new version in production like this:
gcloud app deploy --no-promote
Here the new version is deployed but 0% of the traffic is routed to it. Now use this command to increase the traffic, let say 1%
gcloud app services set-traffic <YOUR_SERVICE> --splits <OldVersionName>=99,<NewVersionName>=1
Monitor your application for a while, and, if there isn't error, continue to increase gradually the traffic, up to be confident and routed 100%
In case of bad version, set the traffic to 0% to the new version and now/or low impact to your users.

Is it possible to get a list of App Engine instances via gcloud?

The title says it all. Just to irritate DRY purists, I'll say it again.
Is it possible to get a list of instances my application is running on via gcloud?
In 2019, You can check the newest document : gcloud app services list - list your existing services
The newest command is:
gcloud app services list
The result will be something like this.
SERVICE NUM_VERSIONS
default 7
App Engine can mean traditional App Engine or Managed VMs, depending on the context. There is only one App Engine app per project, but you can have multiple modules (although only one of those module will serve web traffic, the rest are backend only) and multiple versions of each module.
As pgiecek mention,
gcloud preview app modules list
will show all the modules.
What you might be looking for is all your App Engine versions, for which you will still have to use appcfg
appcfg.py -A <your-project-id> [-M <module>] list_versions
If you are using Managed VMs, it will spin up your app on GCE instances, in which case
gcloud compute instances list
does in fact show your App Engine (MVM) instances.
It seems that currently it is not possible. At the moment gcloud tool supports App Engine (via Preview CLI command groups) but provides only limited number of operations and furthermore they are in BETA. You can check documentation here.
You can only list your existing deployed modules and versions as follows.
gcloud preview app modules list
As of Sep 2019 (Google Cloud SDK 237.0.0):
gcloud app instances list

Application Default Credentials not working locally with App Engine

Having a tough time getting the Default Application Credentials to load in the dataflow SDK when running locally in a java app engine project developing on OS X. Runs fine when deployed.
According to this the dev app server doesn't support them, and you're meant to use the gcloud command line tool's command: gcloud preview app run - but according to the official Google Group for the SDK here that command was deprecated in Jan 2016.
So I seem to be stuck between a rock and a hard place... Does anyone know how to get the Application Default Credentials to work locally with an App Engine app?
I'm trying to use the Dataflow API and it just throws up when it starts making use of the cloud storage api which is the first thing the Pipeline does because it can't seem to load the correct credentials from the environment variables ( that are definitely set on the ENV and in the appengine-web.xml <env-variables> element ) or from the ~/.config/cloud/default_application_credentials.json file.
Cheers!
Can you try running the following command and see if it solves it?
gcloud auth application-default login
This is fully supported (but poorly documented) within the dev appserver. There is a very well answered question that gives you step by step instructions here: Unable to access BigQuery from local App Engine development server

Resources