{"id":19766240,"url":"https://github.com/akaliutau/code-as-a-function","last_synced_at":"2025-02-28T04:16:02.044Z","repository":{"id":120056043,"uuid":"455940660","full_name":"akaliutau/code-as-a-function","owner":"akaliutau","description":"Using Spring Boot applications to run as a Cloud Functions at GCP","archived":false,"fork":false,"pushed_at":"2022-02-06T21:25:56.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-11T00:13:32.231Z","etag":null,"topics":["gcp","gcp-cloud-functions","serverless"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akaliutau.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-05T17:42:14.000Z","updated_at":"2022-02-06T21:37:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"41fea87e-5711-4303-b31a-336dc0e00812","html_url":"https://github.com/akaliutau/code-as-a-function","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akaliutau%2Fcode-as-a-function","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akaliutau%2Fcode-as-a-function/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akaliutau%2Fcode-as-a-function/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akaliutau%2Fcode-as-a-function/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akaliutau","download_url":"https://codeload.github.com/akaliutau/code-as-a-function/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241099621,"owners_count":19909577,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gcp","gcp-cloud-functions","serverless"],"created_at":"2024-11-12T04:23:29.028Z","updated_at":"2025-02-28T04:16:02.027Z","avatar_url":"https://github.com/akaliutau.png","language":"Java","readme":"# About\n\nThese are examples of applications to run in a serverless environment at GCP\n\n# Description\n\n## code-as-a-function\n\nThis is the minimal app to run as a Cloud Function at GCP\n\n\n## springboot-as-a-function\n\nThis is an example of  minimal Spring Boot app to run as a Cloud Function at GCP\n\n# Local testing\n\n```\nexport MAIN_CLASS=functions.WordCounterApp\nexport PROJECT_ID=\u003cproject_id\u003e\nmvn -pl springboot-as-a-function function:run\n```\n\nIn other console invoke the following command:\n\n```\n./send_local_message.sh \"hello big world\"\n```\n\nand see how Function processes the event (must count all 3 words in message). In real situation the message from Pub/Sub topic will be forwarded to app.\n\n# Deployment\n\n1. Create a new Pub/Sub topic to be linked to Function and a topic to publish the results to\n\n```\ngcloud config set project \u003cproject_id\u003e\ngcloud pubsub topics create cf-trigger\ngcloud pubsub topics create cf-results\n```\n\n2. Build the app by running:\n\n```\nmvn -pl springboot-as-a-function package\n```\nThis command will build in the target/deploy directory the JAR file to deploy to GCP\n\n3. Deploy the JAR that you created by running\n\n```\ngcloud functions deploy sbaaf-gcp-background \\\n--entry-point org.springframework.cloud.function.adapter.gcp.GcfJarLauncher \\\n--runtime java11 \\\n--trigger-topic cf-trigger \\\n--source ./springboot-as-a-function/target/deploy \\\n--set-env-vars PROJECT_ID=\u003cproject_id\u003e\n--memory 512MB\n```\nwhere the parameter `--trigger-topic` which topic will trigger the function invocation when new messages are published to it.\n\nIn some cases this command may be need to enabling service [cloudfunctions.googleapis.com] on project. The deployment normally takes 1-3 min.\nThe deployed function is available at `https://console.cloud.google.com/functions/list?project=project_id` \n\n4. Invoke the background function by publishing a message to topic, the outcome must be the same as in Local testing:\n\n```\ngcloud pubsub topics publish cf-trigger --message=\"hello big world\"\n```\nThe result of execution should be visible in logs, and in cf-results topic\n\n\n# References\n\n[1] https://docs.spring.io/spring-cloud-function/docs/current/reference/html/gcp.html\n\n[2] https://github.com/spring-cloud/spring-cloud-function\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakaliutau%2Fcode-as-a-function","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakaliutau%2Fcode-as-a-function","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakaliutau%2Fcode-as-a-function/lists"}