Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/siddhant-k-code/run-cloud-functions-locally
Run Cloud Functions Locally or in Gitpod
https://github.com/siddhant-k-code/run-cloud-functions-locally
cloud-functions gitpod local serverless
Last synced: 2 months ago
JSON representation
Run Cloud Functions Locally or in Gitpod
- Host: GitHub
- URL: https://github.com/siddhant-k-code/run-cloud-functions-locally
- Owner: Siddhant-K-code
- Created: 2024-04-27T10:20:47.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-04-27T11:22:24.000Z (8 months ago)
- Last Synced: 2024-10-12T00:28:27.741Z (3 months ago)
- Topics: cloud-functions, gitpod, local, serverless
- Language: Python
- Homepage:
- Size: 1.95 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Run Cloud Functions Locally π©οΈπ
Welcome to the exciting realm of cloud functions, where the magic of serverless computing comes alive on your local machine! This README will guide you through the enchanting process of setting up and running cloud functions locally, ensuring a pristine, isolated development environment with the aid of [**Gitpod**](https://www.gitpod.io/). π§ββοΈβ¨
## Premise ποΈ
For this magical journey, Python will serve as our trusty runtime language. To avoid any mystical contamination in our local environment, I've set everything up in a dedicated Gitpod workspace. It's like conjuring your very own wizard's tower for code experimentation! π°
Bypass the implementation steps by leaping straight into this repository in Gitpod! Click the button below to teleport there (it's pre-configured for convenience π):
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/Siddhant-K-code/run-cloud-functions-locally)
## Implementation π οΈ
First, let's enchant our `requirements.txt` file with a sprinkle of dependencies:
```txt
functions-framework==3.*
```Now for the spell-castingβthe code! Here's a simple Python script that summons a cloud function:
```python
import functions_framework@functions_framework.http
def main(request):
return f'Hello, {request.json.get("name")}\n'if __name__ == "__main__":
main()
```### Spell Details π§
- `@functions_framework.http`: This powerful spell instructs our script to gear up for responding to HTTP requests as a Cloud Function.
- It's crucial to always send a response back. Ignoring requests is a no-no in both the arcane and coding worldsβit prevents errors and keeps the magical and digital flows balanced.## Execution π
It's time to animate our cloud function! Open your terminal (ensure it's not engaged with other magical commands) and recite the following spell:
```sh
functions-framework --target=main
```Open another terminal window (think of it as opening a portal to another dimension) and invoke your newly minted function:
```sh
curl -X POST -H "Content-Type: application/json" -d '{"name":"Siddhant"}' http://localhost:8080
```If the cosmic energies align and your incantation is precise, you will be greeted with:
```sh
Hello, Siddhant
```## Epilogue π
Remember, the `functions-framework` is capable of more than just HTTP functions; it can also initiate event-driven functions. Perhaps that's an adventure we'll embark upon in the future!
## References π
For more spells and scholarly knowledge, consult these ancient tomes (or just click here):
- [Google Cloud Functions Framework Python](https://github.com/GoogleCloudPlatform/functions-framework-python)
Happy coding, and best wishes on your serverless quest! <3