How to Setup Anypoint Flex Gateway

Venkatesh Jujarao
Another Integration Blog
6 min readMar 1, 2023

This article explains on high-level what is Flex Gateway and how to setup the Flex Gateway on Linux EC2 instance and secure the downstream API by enforcing the policy on the API Manager

What is Flex Gateway

Anypoint Flex Gateway is MuleSoft’s new ultra-fast gateway designed to manage and secure APIs running anywhere. The gateway is built to deliver the performance required for the most demanding applications while providing enterprise-grade security and management.

Reference — Understanding Anypoint Flex Gateway: Overview and Introduction | MuleSoft Developers

How Flex Gateway is different than typical Mule proxy?

Anypoint Flex Gateway is a lightweight standalone gateway that can serve as a proxy for any API, including non-Mule APIs. It can run on major Linux distributions, as a containerized application using a MuleSoft supported OCI image, and as a Kubernetes-native ingress controller or API gateway.

Unlike the existing API gateway, which is embedded into Mule Runtime and depends on Mule applications to work, Anypoint Flex Gateway has a small footprint that allows for installation on the same resource, cluster, and network as the upstream target APIs, delivering sub-second response times.

There are many benefits of Flex Gateway, for more details please refer Flex Gateway | MuleSoft Documentation

One of the key differences between proxy and flex gateway is, in typical Mule proxy for securing non-mule applications it is required to deploy Mule application with minimum 0.1 vCore and 1 worker configuration. But in Flex gateway we don’t need to deploy any Mule application instead we need to deploy the flex gateway as a service.

Difference between typical Mule Proxy and Anypoint Flex Gateway

Now we understood what Flex Gateway is, let’s see how that can be installed and protect the non-mule application through MuleSoft client enforcement policy.

Anypoint Flex Gateway runs in two modes —

1. Local Mode and

2. Connected Mode.

In this article we are going to focus on the Connected Mode. For more details about Flex Gateway Mode refer — Flex Gateway Modes | MuleSoft Documentation

Before directly jumping on Flex Gateway installation, we need a Linux instance. For this walkthrough we are going to use AWS Linux EC2 instance.

For details about how to setup AWS EC2 instance please refer —

Create an AWS EC2 Instance | by Venkatesh Jujarao | Feb, 2023 | Medium

  • Now we have the EC2 instance let's start installing the Flex Gateway.

Install Flex Gateway on AWS EC2 Instance

  • MuleSoft made it very easy with predefined commands to install the Flex Gateway.
  • First go to your Anypoint Platform runtime manager and configure the flex Gateway.

Runtime Manager → Flex Gateway

  • Select OS (Here we are going to use Amazon Linux 2)
  • Run the command mentioned in “Set up your Flex Gateway” section.
1. Install Flex Gateway
2. Register your gateway
3. Start the gateway

Notes -

If you are getting any error running the 2nd Command that might be because of the permission issue with conf.d folder, update the permission with sudo chmod 777 conf.d (first check the current permission of the folder and make a note of it) and run the 2nd command again without sudo. Once the 2nd command ran successfully change the permission of the folder back to previous state.

  • Check that the gateway is running correctly.
systemctl list-units flex-gateway*

Now Flex Gateway is setup correctly, let’s create API on the API Manager.

Note

Here we have just configured the single replica, check below article to understand how to configure multiple replicas — Anypoint Flex Gateway — Configure Replicas | by Venkatesh Jujarao | May, 2023 | Medium

Expose APIs through Flex Gateway

  • Go to API Manager & add new API.
  • Select Flex Gateway and click next.
  • Select API from exchange if already available or create new one.
  • Provide implementation URI.
  • Review all the configuration and click on Save and Deploy
  • With this configuration part is completed, identify your AWS instance public IP/URL and access same from browser with below endpoint.

http://{host/IP}:{port}/{basepath}/{resource}

So, the URL will look like — http://{host}:80/v2/api/get

  • With above screenshot we can see that the request is getting routed to httpbin.org/get API from Flex Gateway (deployed on AWS EC2 instance).

Secure Non-Mule Application by Applying Policies to APIs Managed by Flex Gateway

  • Go to API Manager and apply the policy.
  • After policy is applied make a call to the API, we will get a pop-up to enter valid credentials.
  • If we have enter the invalid credentials then access won’t be provided to the API.
  • Let’s register the client and provide valid credentials.
  • Now our downstream API is secure, and we can successfully make a call to httpbin.org/get service via Flex Gateway.

Monitor the API Traffics and Logs through Anypoint platform.

Summary

In this article we learned

  • What is Flex Gateway is and how it's different from typical MuleSoft proxy.
  • How to install the Flex Gateway on AWS Amazon Linux EC2 instance.
  • How to secure our API by applying policy on the API Manger.
  • How to check the stats of our API.

For more detail understanding about Flex Gateway please refer to MuleSoft documentation.

Looking for flex gateway setup in local mode then refer this articleFlex Gateway Setup — Local Mode. This article is an extension of my… | by Venkatesh Jujarao | Another Integration Blog | May, 2023 | Medium

--

--