This repo shows with the simple example how to manage Java-based serverless APIs build with Azure functions. It uses azure-functions plugin to integrate APISIX with Azure Serverless Function as a dynamic upstream to proxy all requests for a particular URI to the Microsoft Azure Cloud.
Note that the same plugin can be used with other serverless solutions.
This repo demonstrates followings:
- Expose serverless APIs as upstream services.
- Secure serverless APIs with Apache APISIX authentication plugins.
- Apply rate limiting policies.
- apisix_conf - This folder contains Apache APISIX configuration file.
- apisix_log - Apache APISIX log files are generated in this folder.
- cmds - All curl commands examples can be found in this folder.
- etcd_conf - APISIX etcd storage configuration file.
- upstream - The folder has Java project with two functions source code: Products and Reviews.
- Docker
- Azure Account
- Azure CLI
- Java Developer Kit, at least version 8
- Maven
- Azure Functions Core Tools
- Visual Studio Code
- Azure Functions Core Tools (min. version 2.6.666)
- Azure Functions extension for Visual Studio Code
To run Apache APISIX and Azure functions locally, you can follow these steps:
- Run
docker compose up
command from the root folder of the project:
docker compose up -d
Above command will run Apache APISIX and etcd together with Docker.
- Then, navigate to
/upstream
folder:
mvn clean install
mvn azure-functions:run
The two functions will start in a terminal window. You can request both serverless APIs in your browser:
For example:
http://localhost:7071/api/products
http://localhost:7071/api/reviews
- Next, we deploy functions code to Azure Function App by running below cmd
mvn azure-functions:deploy
Or you can simply follow this tutorial on how to deploy the function project to Azure
Note that the function app name is randomly generated based on your artifactId, appended with a randomly generated number. In the tutorial cmds, the function app name
serverless-apis
is mentioned.
Just to make sure our function works, we can test an invocation call directly requesting it URL in the browser:
https://serverless-apis.azurewebsites.net/api/products
https://serverless-apis.azurewebsites.net/api/reviews
Clean up Azure resources when you are finished:
az group delete --name java-functions-group
For more details, see the text version of full tutotial https://api7.ai/blog/manage-serverless-apis-with-apache-apisix.