Azure FaaS¶
Introduction¶
After reading about the microservice implementation I created, this page will provide more clarity pertaining to my theory of the evolution of the microservice.
Theory¶
These days, “serverless” and “functions-as-a-service” (FaaS) have found themselves at the early side of the hype cycle. Some folks have gone so far to say that serverless and functions are the next evolution of microservices, and that you should just skip the whole microservices architecture trend and go right to serverless. Just as you’d expect, this is a bit hyperbolic; by which you shouldn’t be surprised. There’s a lot of exciting, new technology available to us as architects and developers to improve our ability to achieve our business outcomes. What we need is a pragmatic lens through which to judge and apply these new technologies. Although as technology practitioners, it’s our responsibility to keep up with the latest technology, it’s equally our responsibility to know when to apply it in the context of our existing technology and IT departments.
Not covered by this text is my own theory; the largest driving factor for optimization in cloud deployments are costs. Simply explained, a function (running on Azure for example) doesn’t require a constant container being ran by the cloud. It will, upon being requested wake up and serve the function over the cloud and then gracefully exit once the function is done being executed.
Implementation¶
In order to get started I installed the Azure plugin into VSCode & logged into my Student account (which also has student credit enabled for this demonstration). Using the FaaS Python template I quickly rolled out the entire FaaS and deployed it to Azure.
import logging
import azure.functions as func
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
name = req.params.get('name')
if not name:
try:
req_body = req.get_json()
except ValueError:
pass
else:
name = req_body.get('name')
if name:
return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
else:
return func.HttpResponse(
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response. This is a FaaS Ramses Demo",
status_code=200
)
And it can be seen being run successfully here: