# Develop Serverless Applications on Cloud Run: Challenge Lab - GSP328

## **Overview**

In a challenge lab you’re given a scenario and a set of tasks. Instead of following step-by-step instructions, you will use the skills learned from the labs in the course to figure out how to complete the tasks on your own! An automated scoring system (shown on this page) will provide feedback on whether you have completed your tasks correctly.

When you take a challenge lab, you will not be taught new Google Cloud concepts. You are expected to extend your learned skills, like changing default values and reading and researching error messages to fix your own mistakes.

To score 100% you must successfully complete all tasks within the time period!

This lab is recommended for students who have enrolled in the [Develop Serverless Applications on Cloud Run](https://www.cloudskillsboost.google/course_templates/741) course. Are you ready for the challenge?

## **Setup**

### Before you click the Start Lab button

Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click **Start Lab**, shows how long Google Cloud resources will be made available to you.

This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.

To complete this lab, you need:

* Access to a standard internet browser (Chrome browser recommended).
    

**Note:** Use an Incognito or private browser window to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.

* Time to complete the lab---remember, once you start, you cannot pause a lab.
    

**Note:** If you already have your own personal Google Cloud account or project, do not use it for this lab to avoid extra charges to your account.

## **Challenge scenario**

Pet Theory, a veterinary practice, is eager to adopt serverless architecture for modernizing their current systems.

In this challenge lab, as a member of the development team, your assignment is to transition a specific service to a serverless framework. It's crucial to follow the detailed instructions given to accomplish this task successfully.

### Architecture overview

For this project, Pet Theory has selected their current monolithic Billing application to undergo transformation into a serverless model.

Throughout this lab, your responsibility is to execute this architectural upgrade, ensuring a seamless transition to the serverless design.

![Architecture diagram](https://cdn.qwiklabs.com/iqU2yEJH%2FtmFyBvZoE0PWT5iiCUSefFq2EcCvRcAeuQ%3D align="left")

The development team will provide either the code or an image to be deployed as part of the solution.

## **Developing a minimal viable product (MVP)**

You will build a prototype solution for Pet Theory that meets the following high level requirement specification:

| **Ref** | **Definition of Done** |
| --- | --- |
| 1 | Deploy Staging Architecture |
| 2 | Deploy Prod Architecture |
| 3 | Secure Access between components in the Prod Architecture |

## **Provision the lab environment**

During the lab, ensure the environment is provisioned to support the deployment of the resources.

1. Open a [Cloud Shell](https://ssh.cloud.google.com/cloudshell/editor?&shellonly=true) in an Incognito Browser Window.
    
2. Set the default project for the environment:
    

```apache
gcloud config set project \
$(gcloud projects list --format='value(PROJECT_ID)' \
--filter='qwiklabs-gcp')
```

3. Set the region for the run deployments:
    

```apache
gcloud config set run/region us-west1
```

4. Set the Cloud Run platform type:
    

```apache
gcloud config set run/platform managed
```

5. Clone the repo with the Pet Theory code:
    

```apache
git clone https://github.com/rosera/pet-theory.git && cd pet-theory/lab07
```

**Note:** You have been given access to the development repository. Note the location and use the assets to build to the stated requirement.

## **Task 1. Enable a public service**

### Overview

1. Set up a Rest API for the billing service. Use the information in the table below:
    

| **FIELD** | **VALUE** |
| --- | --- |
| Billing Image | billing-staging-api:0.1 |
| Billing Service | `public-billing-service-461` |
| Authentication | unauthenticated |
| Code | pet-theory/lab07/unit-api-billing |

### Architecture

![Pet Theory Challege Lab architecture diagram](https://cdn.qwiklabs.com/8dBgyQ%2BdU%2BiNlwvUBUvgIx%2FZK3M6wZU45ZWVvZgH92M%3D align="left")

2. Using the available code, deploy the Billing Service.
    

### Assessment

To complete this task successfully, you are required to implement the following:

* Build an image using Cloud Build.
    
* Deploy a Cloud Run service as an unauthenticated service.
    
* Test service responds when the endpoint is accessed.
    

**Note:** Activity Tracking can take some time to register. Wait 30 seconds before retrying.

Click **Check my progress** to verify that you've performed the above task.

Deploy a Public Billing Service

**Check my progress**

## **Task 2. Deploy a frontend service**

### Overview

* Set up a Frontend Service. Use the information in the table below:
    

| **FIELD** | **VALUE** |
| --- | --- |
| Image Name | frontend-staging:0.1 |
| Service Name | `frontend-staging-service-105` |
| Authentication | unauthenticated |
| Code | pet-theory/lab07/staging-frontend-billing |

### Architecture

![Pet Theory Challenge Lab architecture diagram](https://cdn.qwiklabs.com/%2FQFrJR%2B%2FcGwmGEa1nwqzmhxhKCGyCPoA9kIOjk81bls%3D align="left")

### Assessment

To complete this section successfully, you are required to implement the following tasks:

* Build an image using Cloud Build.
    
* Deploy the image to Cloud Run as an unauthenticated service.
    
* Service should respond when the endpoint is accessed.
    

Click **Check my progress** to verify that you've performed the above task.

Deploy the Frontend Service

**Check my progress**

## **Task 3. Deploy a private service**

### Overview

* The development team updated their application and would like this deployed to the staging environment:
    

| **FIELD** | **VALUE** |
| --- | --- |
| Image Name | billing-staging-api:0.2 |
| Service Name | `private-billing-service-949` |
| Repository | gcr.io |
| Authentication | authenticated |
| Code | pet-theory/lab07/staging-api-billing |

### Architecture

![Pet Theory Challenge Lab architecture diagram](https://cdn.qwiklabs.com/1MEeYHgxetOOc2QpDo8cUP3rKcXp2Uv2BzWc2tWdRF8%3D align="left")

### Assessment: Cloud Run development

To complete this section successfully, you are required to implement the following tasks:

* Delete the existing Billing Service.
    
* Build an image using Cloud Build.
    
* Deploy the image to Cloud Run requiring authentication.
    
* Assign the SERVICE\_URL to an environment variable.
    

Get the URL of the Billing Service:

```apache
BILLING_URL=$(gcloud run services describe private-billing-service-949 \
--platform managed \
--region us-west1 \
--format "value(status.url)")
```

* Service should respond when the endpoint is accessed
    

```apache
curl -X get -H "Authorization: Bearer $(gcloud auth print-identity-token)" $BILLING_URL
```

Click **Check my progress** to verify that you've performed the above task.

Deploy a Private Billing Service

**Check my progress**

## **Task 4. Create a billing service account**

### Overview

* In preparation for the deployment to production, you will need to create a Service Account for the Billing Service:
    

| **FIELD** | **VALUE** |
| --- | --- |
| Service Account | `billing-service-sa-875` |
| Display Name | Billing Service Cloud Run |
| Service Name | billing-service |
| Role | N/A |

### Architecture

![Pet Theory Challenge Lab architecture diagram](https://cdn.qwiklabs.com/CpXydDKvqje9LDQi6euOsI2ifMWMC6OWVVDssOos3ow%3D align="left")

### Assessment: Service Account

To complete this section successfully, you are required to create a service account.

Click **Check my progress** to verify that you've performed the above task.

Create a Billing Service Account

**Check my progress**

## **Task 5. Deploy the billing service**

### Overview

* Associate the new Billing Service Account with Billing Service:
    

| **FIELD** | **VALUE** |
| --- | --- |
| Image Name | billing-prod-api:0.1 |
| Service Name | `billing-prod-service-102` |
| Repository | gcr.io |
| Authentication | authenticated |
| Code | pet-theory/lab07/prod-api-billing |
| Service Account | `billing-service-sa-875` |

### Architecture

![Pet Theory Challenge Lab architecture diagram](https://cdn.qwiklabs.com/1MEeYHgxetOOc2QpDo8cUP3rKcXp2Uv2BzWc2tWdRF8%3D align="left")

### Assessment: Cloud Run development

To complete this section successfully, you are required to implement the following tasks:

* Deploy the image to Cloud Run.
    
* Enable Authentication.
    
* Enable the Service Account.
    
* Service should respond when the endpoint is accessed.
    

Get the URL of the Billing Service:

```apache
PROD_BILLING_URL=$(gcloud run services describe private-billing-service-949 \
--platform managed \
--region us-west1 \
--format "value(status.url)")
```

Access the deployed endpoint:

```apache
curl -X get -H "Authorization: Bearer \
$(gcloud auth print-identity-token)" \
$PROD_BILLING_URL
```

Click **Check my progress** to verify that you've performed the above task.

Deploy the Billing Service

**Check my progress**

## **Task 6. Frontend service account**

### Overview

* Create a new Service Account for the Frontend capable of invoking the Billing Service:
    

| **FIELD** | **VALUE** |
| --- | --- |
| Service Account | `frontend-service-sa-304` |
| Display Name | Billing Service Cloud Run Invoker |
| Service Name | frontend-prod-service |
| Role | run.invoker |

### Architecture

![Pet Theory Challenge Lab architecture diagram](https://cdn.qwiklabs.com/jfpWAjnFUlDAZcybQr8YLcd6BP3MJ2hjgL8kn54L23s%3D align="left")

### Assessment

To complete this section successfully, you are required to implement the following tasks:

* Create a Service Account.
    
* Apply Service Account for Frontend Service.
    
* Give Service Account run.invoker permission.
    
* Bind Account to Service.
    

Click **Check my progress** to verify that you've performed the above task.

Create the Frontend Service Account

**Check my progress**

## **Task 7. Redeploy the frontend service**

### Overview

* Use the new Service Account and redeploy the Frontend Service:
    

| **FIELD** | **VALUE** |
| --- | --- |
| Image Name | frontend-prod:0.1 |
| Service Name | `frontend-prod-service-956` |
| Repository | gcr.io |
| Authentication | unauthenticated |
| Code | pet-theory/lab07/prod-frontend-billing |
| Service Account | `frontend-service-sa-304` |

### Architecture

![Pet Theory Challenge Lab architecture diagram](https://cdn.qwiklabs.com/%2FQFrJR%2B%2FcGwmGEa1nwqzmhxhKCGyCPoA9kIOjk81bls%3D align="left")

### Assessment: Cloud Run development

To complete this section successfully, you are required to implement the following tasks:

* Deploy the image to Cloud Run.
    
* Enable Authentication.
    
* Enable Service Account.
    
* Service should respond when the endpoint is accessed.
    

Click **Check my progress** to verify that you've performed the above task.

Deploy the Frontend Service

**Check my progress**

* Now access the production frontend service to display the user interface.
    

Information on screen is consumed from the private billing service using the service account.

![Pet Theory: Billing Service page](https://cdn.qwiklabs.com/M%2FTji7Eq8Rbs9jQiaeMxXbhftSkVStckjQvkG7ocErk%3D align="left")

---

## Solution of Lab

%[https://www.youtube.com/watch?v=sLarVHSkbro] 

```apache
export REGION=
export TASK_1_SERVICES_NAME=
export TASK_2_SERVICES_NAME=
export TASK_3_SERVICES_NAME=
export TASK_4_SERVICES_NAME=
export TASK_5_SERVICES_NAME=
export TASK_6_SERVICES_NAME=
export TASK_7_SERVICES_NAME=
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724075297802/fd0ddb0b-23c8-4c56-82fc-75a8f54aab20.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724075305344/e7b553c0-bd42-4ab5-8e85-47c14a89c760.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724075310440/f19773ad-55de-462f-892f-6056ab09e6a1.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724075317982/dff0bcfb-13a6-4c4d-aeff-78d05f47eea5.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724075328303/37dc8b02-169b-46d0-b726-8f27a7332fa8.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724075335296/2a5e5b2a-02af-4832-bfb1-a3baee083783.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724075342401/7042c833-dd2b-468f-bf7b-ab47276c45a7.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724075349600/7e4c7ea6-b164-471e-835d-754d4bfc5403.png align="center")

```apache
curl -LO raw.githubusercontent.com/quiccklabs/Labs_solutions/master/Develop%20Serverless%20Applications%20on%20Cloud%20Run%20Challenge%20Lab/quicklabgsp328.sh
sudo chmod +x quicklabgsp328.sh
./quicklabgsp328.sh
```
