2015-08-06

During the last few years, polyglot programming has become the de facto standard. Developers started to choose best of breed languages, frameworks and runtimes to write their code. Initially, it was platform as a service (PaaS) offerings such as Heroku, Engine Yard, Cloud Foundry and OpenShift that encouraged developers to build polyglot applications and services.

Thanks to Docker, it became simpler to design, develop and deploy polyglot code as a part of the new microservices phenomenon. It’s not just the services — even the consumers of microservices are polyglot. Web applications built with contemporary JavaScript frameworks such as AngularJS and Bootstrap; native mobile applications developed in iOS and Android; and IoT applications consume the polyglot microservices. The key enabler of this pattern is the API layer that acts as the glue connecting the services with consumers.

API has become an integral part of application design. Architects and developers are spending significant time in designing the API tier. Netflix  — one of the early adopters of polyglot services and APIs — shared some of the advantages of implementing an API layer in their services architecture. Chris Richardson, the founder of the original Cloud Foundry and an expert in microservices, articulated the importance of API Gateway pattern. According to Chris, not only does the API gateway optimize communication between clients and the application, but it also encapsulates the details of the microservices.

Before implementing an API gateway:



After implementing an API gateway:



Even before microservices and IoT, API lifecycle management has become an important part of application management. Sensing this opportunity, companies such as 3Scale, Apigee, Intel, and Layer 7 have created enterprise-grade API management platforms. One of the recent entrants in this field is Mashape, which introduced Kong, an open source API management platform. Public cloud service providers have started exposing API Gateway as a service. In 2013, Microsoft acquired a Washington DC-based startup called Apiphany which eventually became Azure API Management. Though not a full-fledged API management service, Google also dabbled with API through Cloud Endpoints, a layer to expose the services deployed on App Engine. With the launch of API Gateway, Amazon has officially entered the crowded API management tools market.

Though many consider it to be late, API Gateway plays a significant role in Amazon’s PaaS strategy. In one of my recent articles published at Forbes, I discussed how AWS is all set to disrupt the PaaS market with its NoOps approach. Joe Emison shared a slightly different perspective of the same in his article, How Amazon Web Services Isn’t Winning and the Problems it Poses.

AWS customers can implement API Gateway in many forms. They can launch an AMI running third party API Management platforms such as  3Scale or Intel Mashery. For better control, DevOps teams can also configure Mashape Kong on EC2 running behind an Elastic Load Balancer. But API Gateway has unique advantages for developers and DevOps teams. Especially if they are implementing microservices on AWS Lambda and Amazon EC2 Container Service. When compared to enterprise API management platforms, the AWS offering may fall short of a few features. But this is a V1 service, and Amazon has the tradition of shipping an MVP and making it better with every iteration. Personally, I am not worried about the vendor lock-in of APIs because they can be implemented on other platforms without much disruption to the clients. I am attempting to highlight the capabilities of Amazon API Gateway in the context of microservices deployed on AWS.

Though Amazon API Gateway may not be ideal for every scenario, it is an excellent solution for organizations with significant investments in AWS. Teams that are utilizing Amazon’s ALM services such as CodeCommit, CodeDeploy and CodePipeline will find it very easy to integrate. Finally, if you are developing a microservices application based on Lambda, API Gateway becomes the custodian of your services.



Source: http://aws.amazon.com/api-gateway/details/

1. Elastic, Self-Service and Pay-by-Use API Facade in the Cloud

Like most of the AWS services, Amazon API Gateway is available as a self-service tool for developers and administrators. Instead of launching EC2 instances, installing and configuring gateway software, developers can hit the ground running with API Gateway

API management layer is very similar to web workloads. It’s mostly stateless that needs to be load-balanced to scale. Custom solutions require a combination of ELB and EC2 instances. API Gateway is elastic which can scale-out and scale-in dynamically without manual configuration. With $3.50 per million API calls, the service is one of the affordable gateways in the market. Developers can point and click to implement an API gateway for their existing backends in minutes.

2. Integration With AWS Lambda, IAM and AWS Services

Amazon is heading towards creating a serverless backend infrastructure. Services such as Cognito, DynamoDB, RDS, Directory Services expect the developers to point and click instead of provisioning EC2 instances. AWS Lambda is a big leap in that direction. Developers can create independent, stateless, autonomous code snippets that will be orchestrated at runtime. Until the launch of API Gateway, Lambda snippets were confined to a set of predefined events raised by services such as S3, SNS, Kinesis, and DynamoDB. Developers couldn’t invoke their code on-demand through a REST endpoint. By enabling API Gateway to become the frontend for AWS Lambda, Amazon has enabled a killer scenario. Developers can bring their code and data to AWS and configure the entire stack without ever spinning up VMs. This integration enables a true NoOps platform.

Beyond Lambda, API Gateway is also integrated with IAM for security. Through this developers can authorize access to their APIs. It is also possible to generate custom API keys that are shared with the clients that need direct invocation.  All API calls made to the Amazon API Gateway are logged in CloudTrail, the AWS audit trail service.  This includes APIs to create, modify, delete or deploy REST APIs.

API Gateway can become a proxy for existing AWS service endpoints. Developers can mix and match custom API backends hosted in EC2, Lambda, Elastic Beanstalk, and EC2 Container Service along with third-party APIs such as Salesforce, Twilio, and Twitter. This layer becomes a unified frontend for all the inbound API calls.

3. API Logging, Caching, Throttling, Bursting and Monitoring

Instead of invoking the backend API for every client call, developers can configure caching which will improve performance. Cache settings allow developers to control the way the cache key is built and the time-to-live (TTL) of the data stored for each method. The management API can be invoked to invalidate the cache. The pricing for this feature is based on the size of the cache.

Developers need to protect their backend APIs from deliberate misuse. They may also want to restrict the rate at which the API is invoked. Through throttling, it is possible to set a rate limit of API requests to avoid sudden spikes. API Gateway can also be configured to handle bursts of API calls for specific scenarios. Clients can include automatic retry logic when they receive a 429 HTTP response as a result of throttling. With the right configuration of cache and throttling, developers can increase the performance while securing the backend API.

Since API Gateway is a crucial element of an application, it needs to be monitored for uptime. For custom gateways, administrators need to configure native monitoring combined with agents. Amazon API Gateway integrates with CloudWatch, the one-stop monitoring service for all AWS services. By configuring an IAM role that has write access to CloudWatch logs, API Gateway can be monitored for a variety of metrics.

Configuring Caching, Logging, Monitoring and Throttling

4. API Lifecycle Management

The API facade becomes an important element of applications that needs to integrate with CI/CD pipelines. API Gateway supports staging and versioning that can be aligned with the rest of the application.

For example, developers can have dedicated endpoints for testing, staging, and production stages. Each version of the API can be associated with a custom domain. Administrators can switch multiple versions while keeping the custom domain and endpoint the same. This makes it possible to easily rollback API versions. A/B testing and blue/green deployments can also take advantage of this feature. Through the management API, DevOps can integrate API Gateway with CI/CD pipelines.

5. Payload Modeling and Transformation

One of the advanced features of API Gateway is payload modeling and transformation. This gives developers a chance to modify the JSON schema during the request and response cycles. By defining a template, the request and response payloads can be transformed to reflect a custom schema. This is especially useful in aggregating output from multiple sources into one JSON payload. Though API Gateway doesn’t support importing and exporting API definitions from RAML, it does have a tool to import from Swagger. The Swagger definitions may include pointers to templates that will be used for payload modeling.

Transforming the JSON Payload

Bonus: Native Code Generation

One of the main advantages of using API Gateway is the ability to generate native SDKs for clients. Once the API is deployed, developers can generate SDKs for Android, JavaScript and iOS. Additional platform such as Apache Cordova, Xamarin and Windows Phone may be supported in the future.

Native Code Generation

Summary

Amazon API Gateway may not be comparable to established enterprise offerings such as 3Scale, Apigee, CA, Intel, MuleSoft and Akana. But it does cater to AWS developers through a simple but functional service. Like most of the other AWS services, API Gateway will become mature over a period of time. It may not be perfect but it is a great starting point for developers implementing microservices on AWS.

3scale is a sponsor of The New Stack.

Feature image: “Sandy River in May” by Luke Detwiler is licensed under CC BY 2.0.

The post Five Reasons to Consider Amazon API Gateway for Your Next Microservices Project appeared first on The New Stack.

Show more