This post covers getting started with a very simple Google Cloud Functions API,
a great serverless solution with affordable pricing. This API will pull the
IP address from the HTTP request, and return Hello <source IP>
.
Cloud Functions pricing is pretty affordable for most use cases, assuming you write your functions in such a way that they don't get invoked a few too many millions of times.
Check the official Google docs for accurate and up-to-date pricing, but here's what it looked like at the time of my writing this.
Pricing is broken into a few fees:
Open Google Cloud Functions in your browser.
Create a function.
The API function defined by Function to execute
accepts a
flask.Request
argument.
def hello_world(request):
"""" Return a Hello message to sender of the API call """
return 'Hello {}!'.format(request.remote_addr)
You can leave this blank. It's a list of libraries that will be used.
{}
is all you need.You can now test the URL with curl, your browser, httpie, python, etc.
https://<region>-<project>.cloudfunctions.net/HelloWorld