SylviaBABY commented on a change in pull request #784:
URL: https://github.com/apache/apisix-website/pull/784#discussion_r760804943



##########
File path: website/blog/2021/12/01/apisix-supports-azure-functions.md
##########
@@ -0,0 +1,182 @@
+---
+title: "Apache APISIX intergration with Azure Serverless"
+author: "Bisakh Mondal"
+authorURL: "https://github.com/bisakhmondal";
+authorImageURL: "https://avatars.githubusercontent.com/u/41498427?v=4";
+keywords: 
+- Apache APISIX
+- Azure Functions
+- Microsoft
+- Serverless
+description: This article talks about the recent addition of a new plugin 
`azure-functions`, and gives detailed instructions on how to integrate Azure 
Functions, which is a widely used serverless solution, into the Apache APISIX 
serverless suite.
+tags: [Technology]
+---
+
+> This article talks about the recent addition of a new plugin 
`azure-functions`, and gives detailed instructions on how to integrate Azure 
Functions, which is a widely used serverless solution, into the Apache APISIX 
serverless suite.
+
+<!--truncate-->
+
+Apache APISIX provides support for serverless frameworks for popular cloud 
vendors (more coming on the way). Instead of hardcoding the function URL into 
the application, Apache APISIX suggests defining a route with the serverless 
plugin enabled. It gives the developers the flexibility to hot update the 
function URI along with completely changing the faas vendor to a different 
cloud provider with zero hassle. Also, this approach mitigates authorization 
and authentication concerns from application logic as Apache APISIX has very 
strong authentication support that could be used to identify and authorize 
client consumers to access the particular route with the faas. This article 
talks about the recent addition of a new plugin `azure-functions`, and gives 
detailed instructions on how to integrate Azure Functions, which is a widely 
used serverless solution, into the Apache APISIX serverless suite.
+
+## How azure-functions plugin works
+
+The `azure-functions` plugin lets the users define an upstream to the azure 
`HTTP Trigger` serverless function for a gateway URI. If enabled, this plugin 
terminates the ongoing request to that particular URI and initiates a new 
request to the azure faas (the new upstream) on behalf of the client with the 
suitable authorization details set by the users, request headers, request body, 
params(all these three components are passed from the original request) and 
returns the response body, status code and the headers back to the original 
client that has invoked the request to the APISIX agent.
+
+The plugin supports authorization to azure faas service via API keys and azure 
active directory.
+
+## How to Use Azure Functions with Apache APISIX
+
+The primary goal of the plugin is to proxy the gateway route specified in the 
route configuration to the azure functions URI. This section gives you a 
hands-on how to configure and create a serverless HTTP Trigger on the azure 
cloud.
+
+1. First sign up/in to Microsoft Azure and sets up a trial plan. Azure 
Functions are forever free up to 1 million invocations. To know more about how 
the pricing, visit 
[here](https://azure.microsoft.com/en-us/services/functions/#pricing).
+
+1. Visit the [Azure Portal](https://portal.azure.com/#home) (FYI, azure 
services can be accessed via the web portal, CLI & VSCode. for 
user-friendliness we are using the web).
+    1. First, create a resource group to logically partition your faas that's 
you are going to create.
+    ![create a resource 
group](https://static.apiseven.com/202108/1638349069240-911b8640-2de6-4f82-b75b-fb937b0bad40.png)
+    1. Create a function app with the URL of your choice (I am going to pick 
test-apisix).
+    ![create a function 
app](https://static.apiseven.com/202108/1638349121520-01abe8e6-bc09-4be7-b010-f7baec59f89a.png)
+
+1. Install the [Azure Functions 
extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions)
 into VSCode editor. Upon installation, authenticate via extension and install 
the azure function core tool for local development with:
+
+    ```shell
+    npm install -g azure-functions-core-tools@3 --unsafe-perm true
+    ```
+
+1. Deploy the following snippet to the same function app that we just created 
via the Azure Functions extension panel in VSCode:
+
+    ```javascript
+    module.exports = async function (context, req) {
+    context.log('HTTP trigger invoked on Test-APISIX.')
+
+    const name = req.query.name || (req.body && req.body.name)
+    const responseMessage = name
+        ? 'Hello, ' + name
+        : 'This HTTP triggered function executed successfully. Pass a name in 
the query string or in the request body to generate a personalized response.'
+
+    context.res = {
+        // status: 200, /* Defaults to 200 */
+        body: responseMessage,
+    }
+    }
+    ```
+
+> This snippet takes the name from query parameters (if present, else from the 
request body) and greets the user.
+
+### Activate the azure-functions plugin
+
+The following is an example of how to enable the azure-functions plugin for a 
specific route. We are assuming your HTTP Trigger is deployed and ready to be 
served.
+
+```shell
+# enable plugin for a specific route
+curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: 
edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+    "plugins": {
+        "azure-functions": {
+            "function_uri": 
"http://test-apisix.azurewebsites.net/api/HttpTrigger";,
+            "authorization": {
+                "apikey": "<Generated API key to access the Azure-Function>"
+            }
+        }
+    },
+    "uri": "/azure"
+}'
+```
+
+Now any requests (HTTP/1.1, HTTPS, HTTP2) to URI `/azure` on the APISIX 
gateway will trigger an HTTP invocation to the aforesaid function URI and 
response body along with the response headers and response code will be proxied 
back to the client. For example ( here azure cloud function just take the 
`name` query param and returns `Hello $name`):
+
+```shell
+curl -i -XGET http://localhost:9080/azure\?name=Bisakh
+HTTP/1.1 200 OK
+Content-Type: text/plain; charset=utf-8
+Transfer-Encoding: chunked
+Connection: keep-alive
+Request-Context: appId=cid-v1:38aae829-293b-43c2-82c6-fa94aec0a071
+Date: Wed, 19 Nov 2021 18:46:55 GMT
+Server: APISIX/2.10.2
+
+Hello, Bisakh
+```
+
+Considering, APISIX is also running with `enable_http2: true` on APISIX 
[config-default.yaml](https://github.com/apache/apisix/blob/master/conf/config-default.yaml#L26)
 for port 9081 (say), any `HTTP/2` communication between client and APISIX 
agent will be proxied to the azure faas similar to HTTP/1.1 and responses will 
be proxied back to the client with proper headers. For example:
+
+```shell
+curl -i -XGET --http2 --http2-prior-knowledge 
http://localhost:9081/azure\?name=Bisakh
+HTTP/2 200
+content-type: text/plain; charset=utf-8
+request-context: appId=cid-v1:38aae829-293b-43c2-82c6-fa94aec0a071
+Date: Wed, 19 Nov 2021 18:46:56 GMT
+server: APISIX/2.10.2
+
+Hello, Bisakh
+```
+
+### Deactivate the azure-functions plugin
+
+Now, to disable the plugin simply remove the corresponding JSON configuration 
in the plugin configuration to disable the `azure-functions` plugin and add the 
suitable upstream configuration. APISIX plugins are hot-reloaded, therefore is 
no need to restart APISIX.

Review comment:
       APISIX ➡️ Apache APISIX




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to