App Engine: Hello World!
Create New Project
At home dashboard click on the 3 circles next to the current project name to get to the project dashboard
Click NEW PROJECT
Customize your project name to make it easier to access
Enter a unique name for the project that is descriptive and you can remember
Then hit CREATE button
Click back into the project menu to select the new project
Click into project to select
Upper left hand corner should show name
Next let's go into the Cloud linux shell upper left hand corner by clicking the >- sign
Welcome to Cloud Shell! Type "help" to get started.
Your Cloud Platform project in this session is set to hello-world-uconn-app.
Use “gcloud config set project [PROJECT_ID]” to change to a different project.
admin_@cloudshell:~ (hello-world-uconn-app)$
Use “gcloud config set project [PROJECT_ID]” to change to a different project.
By default you will be set into the project that you selected when entering shell mode
Create a directory for the project mkdir helloworld
$ mkdir helloworld
Use the Open Editor button in the right hand side of the screen to allow for the code to placed into the project directory
Highlight the helloworld directory
Highlight the directory and right click
type in main.py (note all app engine python processes start with main.py)
main.py
=========================================================
from flask import Flask
# If `entrypoint` is not defined in app.yaml, App Engine will look for an app
# called `app` in `main.py`.
app = Flask(__name__)
@app.route('/', methods=['GET'])
def hello():
"""Return a friendly HTTP greeting."""
return 'Hello UCONN World!\n'
if __name__ == '__main__':
# Used running locally deploying to Google App
# Engine, a webserver
# configured adding an `entrypoint` to app.yaml.
app.run(host='localhost', port=8080, debug=True)
=========================================================
cut and paste the code above into the on screen editor
Note: This web app is a simple web service responding to HTTP GET requests with the message Hello UCONN World!.
Create a new file for requirements.txt (note: the helloworld directory needs to be highlighted when creating the file)
requirements.txt
=====================================
Flask==3.0.1
======================================
cut and paste into the file (note: may need to use ctrl-v to paste)
Again making sure the helloworld directory is selected create a new file called app.yaml
app.yaml
=========================================================
runtime: python39
=========================================================
cut and paste into the file (note: may need to use ctrl-v to paste)
next use menu to file save all
toggle back to terminal mode by clicking Open Terminal on right hand side of the screen.
Type “cd helloworld”
To change into that directory
$ cd helloworld
While positioned within the helloworld directory type
gcloud app deploy
$ gcloud app deploy
Click Authorize
Choose 18 for us-east-1
Please choose the region where you want your App Engine application located:
[1] asia-east1 (supports standard and flexible)
[2] asia-east2 (supports standard and flexible and search_api)
[3] asia-northeast1 (supports standard and flexible and search_api)
[4] asia-northeast2 (supports standard and flexible and search_api)
[5] asia-northeast3 (supports standard and flexible and search_api)
[6] asia-south1 (supports standard and flexible and search_api)
[7] asia-southeast1 (supports standard and flexible)
[8] asia-southeast2 (supports standard and flexible and search_api)
[9] australia-southeast1 (supports standard and flexible and search_api)
[10] europe-central2 (supports standard and flexible)
[11] europe-west (supports standard and flexible and search_api)
[12] europe-west2 (supports standard and flexible and search_api)
[13] europe-west3 (supports standard and flexible and search_api)
[14] europe-west6 (supports standard and flexible and search_api)
[15] northamerica-northeast1 (supports standard and flexible and search_api)
[16] southamerica-east1 (supports standard and flexible and search_api)
[17] us-central (supports standard and flexible and search_api)
[18] us-east1 (supports standard and flexible and search_api)
[19] us-east4 (supports standard and flexible and search_api)
[20] us-west1 (supports standard and flexible)
[21] us-west2 (supports standard and flexible and search_api)
[22] us-west3 (supports standard and flexible and search_api)
[23] us-west4 (supports standard and flexible and search_api)
[24] cancel
Please enter your numeric choice: 18
Select Y when asked Do you want to continue
Creating App Engine application in project [hello-uconn-world] and region [us-east1]....done.
Services to deploy:
descriptor: [/home/john_iacovacci1/hello/app.yaml]
source: [/home/john_iacovacci1/hello]
target project: [hello-uconn-world]
target service: [default]
target version: [20220911t221324]
target url: [https://hello-uconn-world.ue.r.appspot.com]
target service account: [App Engine default service account]
Do you want to continue (Y/n)?
Finally the app is deployed
Beginning deployment of service [default]...
Uploading 3 files to Google Cloud Storage
33%
67%
100%
100%
File upload done.
Updating service [default]...done.
Setting traffic split for service [default]...done.
Deployed service [default] to [https://hello-uconn-world.ue.r.appspot.com]
You can stream logs from the command line by running:
$ gcloud app logs tail -s default
To view your application in the web browser run:
$ gcloud app browse
john_iacovacci1@cloudshell:~/hello (hello-uconn-world)$
j
To execute go to compute and select app engine and Dashboard
Then click on your application link in the right hand corner
In your browser window it should say “Hello UCONN Stamford World”
No comments:
Post a Comment