Using API Gateway as a Single Entry Point for Web Applications and API Microservices
AWS Architecture BlogUsing API Gateway as a Single Entry Point for Web Applications and API Microservicesby Anandprasanna Gaitonde and Mohit Malik | on22 OCT 2019| inAdvanced (300),Amazon API Gateway,Architecture,Intermediate (200)|Permalink|ShareIntroductionThe benefits of high availability, scalability, and elasticity that AWS offers has proven to be a boon for Software-as-a-Service (SaaS) providers. AWS has also made it seamless to adopt microservices architectures for modernizing these SaaS applications, as well as providing API-based access for external applications.An API management layer such asAmazon API Gatewayis a natural choice for customers to expose APIs externally in a secure and highly scalable manner. However, as they adopt the cloud for their software applications and services, these providers may spin up redundant AWS environments to support them for multiple customers. This is typically driven by some unique requirements for each of their customers.However, there is potential to create a multi-tenant microservices architecture using the capabilities of API Gateway. This architecture utilizes the same instance of microservice to serve different customers, thereby leading to a better utilization of the environment and optimized from a cost perspective. This configuration requires providers to support white-labelling of domains to cater to each of their customer as well as support identification of the customer domain for handling customized business logic for each customer in the backend microservices.This blog post talks about a reference architecture that allows API Gateway to act as single entry point for external-facing, API-based microservices and web applications across multiple external customers by leveraging a different subdomain for each one.Amazon API Gateway: A Single Entry-PointUsing a single API Gateway in the architecture across multiple web portal applications and microservices is an important consideration towards the goal of reusability of components and cost optimization.Amazon API Gateway provides a highly scalable solution to create and publish RESTful and WebSocket APIs. It provides flexibility in choosing multiple backend technologies such asAWS Lambdafunctions,AWS Step Functionsstate machines, or call HTTP(s) endpoints hosted onAWS Elastic Beanstalk,Amazon EC2, and also non-AWS hosted HTTP based services.API Gateway allows for handling common API management tasks such as security, caching, throttling, and monitoring. While its primary objective is to provide that abstraction layer on top of your backend APIs and microservices, it can also allow backends to be simple web applications for web portal access orAmazon S3buckets for providing access to static web content or documents.Along with above capabilities, the following key features of API Gateway help to create the architecture described here.Custom Domain Names support:When an API is deployed using API Gateway, the default API endpoint domain name is not user friendly as can be seen here:https://api-id.execute-api.region.amazonaws.com/stageapi-idis generated by API Gateway;regionis specified by you when creating the API; andstageis specified by you when deploying the API.The default API endpoint can be difficult to recall and not user-friendly. To provide a simpler and more intuitive URL for your API users, it allows you to specify a custom domain name such ascustomer1.example.comvia its integration with AWS Certificate Manager, which allows for SSL certificate-based validation of the sub-domains. API Gateway allows you to map multiple sub-domains to a single API endpoint allowing you to white-label the domains based on an external customer’s requirement.API request /response transformation:API Gateway allows you to specify the integration of each path of the API endpoint separately. This allows you to route API requests for each path to a separate backend endpoint and at the same time apply any request/response transformations, such as customer header insertion or modification of existing headers to manage any custom handling of APIs.Architecture and Its BenefitsIn the architecture shown in the diagram below, the features explained in this blog are utilized.This architecture is an example of a typical SaaS provider who wants to offer its services to other enterprises and needs to support white-labeling domains for this web and API infrastructure. This is achieved using the following steps:A single domain ofexample.comcan be registered with a domain registrar and you can create subdomains by creating CNAME records for examplecustomer1.example.com,customer2.example.comby updating DNS information with the domain registrar. This can be handled by AWS’s own DNS and Registrar serviceAmazon Route 53or can be any third party domain name provider.Once complete, AWS providesAWS Certificate Manager(ACM) to create a certificate for the following domains:example.comand*.example.com. This makes sure that the ACM certificate once applied to the API Gateway can allow for multiple subdomains to be served by it.Using the certificate created in ACM, you can create custom domain for the API endpoint. In this example this API endpoint will serve two subdomains for two different external customers and specifying base path mappings as needed. The following two subdomains are created as custom domains using this capability:customer1.example.comandcustomer2.example.com.Note: Make sure to add CNAME records for customer1 and customer2 at your DNS provider to point to the target domain name created within your API Gateway for each of the two customer sub-domains.The API Endpoint is then configured with the following API resources:HTTP integration of /service1 to route traffic to the ELB endpoint of microservice hosted on an ECS clusterHTTP integration of /service2 to route traffic to the ELB endpoint of web application hosted on an EC2 cluster/docs API resource is integrated with AWS S3 for any static documentsAPI Gateway allows you to capture the FQDN of the URL and map it to Custom Headers or Query String Parameters which are then sent to the backend service integrated with the corresponding API resource and the HTTP method. For example we can create a custom header called “Customer” to forwardcustomer1orcustomer2to the backend application for customer-specific business logic. This is done using the Method Request parameters and Integration Request configuration within API Gateway.SummaryAs you can see, this is one of the approaches to use an API Gateway as a single entry-point for API-based microservices and web application assets. This allows you to use infrastructure more cost effectively without losing the advantages of scaling when demand to your applications grow. You can read more about working withAPI GatewayandRoute 53 DNSin AWS Documentation and use these capabilities to create architectures to suit your specific requirements.TAGS:amazon api gateway,application load balancer,aws lambda,certification,microservices,Route 53Anandprasanna GaitondeAs an AWS Solutions Architect, Anandprasanna Gaitonde is responsible for helping customers design and operate Well-Architected solutions to help them adopt AWS cloud successfully. He focuses on AWS Networking & Serverless technologies to design and develop solutions in the cloud across industry verticals. He has Solutions Architect Professional and Advanced Networking certifications and holds a Master of Engineering in Computer Science and post-graduation degree in Software Enterprise Management.Mohit MalikMohit Malik is a Solutions Architect at Amazon Web Services. He lives in the Seattle area and helps customers architect and optimize applications on AWS. Mohit holds a master’s degree in Computer Science from University of Southern California.
Introduction The benefits of high availability, scalability, and elasticity that AWS offers has proven to be a boon for Software-as-a-Service (SaaS) providers. AWS has also made it seamless to adopt microservices architectures for modernizing these SaaS applications, as well as providing API-based access for external applications. An API management layer such as Amazon API Gateway […]
Anandprasanna Gaitonde
Advanced (300) Amazon API Gateway Architecture Intermediate (200)