I’m currently working through a series of GCP exercises. I’ve been able to complete the first 3 which involved PubSub and Cloud Functions. Exercise 4 is as follows:
-
Write a Cloud Function which is triggered via Pub/Sub topic
-
Write logic to read JSON message from pub/sub topic with schema
-
fileName
-
fileContent
-
Read message from pub/sub topic and write in Google Cloud Storage with fileName and fileContent as received in pub/sub message. Create the bucket manually from console or from code
-
Create a service account and give it permission to write data in google cloud storage
-
Use this service account while deploying the cloud function
-
Create pub/sub topic from console or CLI, publish JSON message in format mentioned above and test
We have access to a repo with the correct answers. I copied the correct answer but it is failing to deploy. My code includes Gson. When I run the deploy command it completes its build but fails to deploy. Two of the main erros are:
Exception in thread “main” java.lang.RuntimeException: Could not construct an instance of com.GcpExercies.GcpExercies.Ex4.PubSubStorageFunction: java.lang.reflect.InvocationTargetException
Caused by: java.lang.ClassNotFoundException: com.google.gson.Gson
Gson dependency is in my pom.xml file. I’m really not sure what to do. Any advice would be appreciated. Apologies if this question is poorly structured or if it is missing information. Please ask and I will provide you with anything you need.
Github Repo: https://github.com/CuBot137/GcpExercises.git
What I have tried so far
Changed to target
Added Ex4 functions.Ex4.PubSubStorageFunction
Changed –source=target to –source=target/deploy…failed
Instead of using the CloudEvent interface I am now using the BackgroundFunction interface
Added compile to gson dependency