What is AWS API Gateway?

AWS API Gateway is an API management service that allows developers to publish, secure, monitor, and maintain APIs. This fully managed service lets you create APIs of any scale with a few clicks via the AWS management console. These APIs act as the gateway for applications to access business logic, data, and functionality from back end services.

You can use API Gateway to build APIs for web applications running on any Amazon service, including Elastic Compute Cloud (EC2), Elastic Container Service (ECS), and Elastic Beanstalk.

Amazon API Gateway pricing

API Gateway allows you to pay only for the time you use the APIs. Amazon does not require upfront commitments or minimum fees. You only pay for the API calls received and data transferred for stateless APIs (i.e., HTTP and REST APIs). There are charges for transferring data out with a private API. However, there are fees for AWS PrivateLink when you use a private API in AWS API Gateway. 

API Gateway offers a data caching option with hourly fees varying according to the selected cache size. For stateful (WebSocket) APIs, you only pay for the time the APIs are in use, depending on the number of messages received and sent and the connection time (in minutes). You can receive and send up to 128 KB of messages. You pay for increments of 32 KB—a heavier message will be billed as two or more messages

API Gateway offers a free tier that includes one million messages, one million HTTP API calls, and one million REST API calls. It provides 750,000 minutes of connection time per month for 12 months.

Caching helps improve performance and accelerate API execution. You can specify the size of the dedicated caches for each API stage—pricing is based on set hourly rates for every stage’s cache. There are no long-term commitments.

Amazon API Gateway pricing examples

HTTP APIs

Example #1: An API invokes Lambda to retrieve dynamic content

The serverless web application receives 5,000 page loads per minute, amounting to 216 million requests in a 30-day month. If billed at $1.00 per million requests, the total costs will be $216. 

Example #2: An API uploads data to the HTTPS back end

The API receives 30 calls per minute while uploading documents that are 4.5 MB on average. Requests are billed at 512KB (so an average upload counts as 8.79 requests). A 30-day month has 11,390,000 API calls billed at $1 per million, costing a total of $11.39.

REST APIs

Example #1: An edge-optimized API in US West (Oregon)

The API gets four million calls/month, each returning an average response of 3 KB without caching. The pricing in the US West (Oregon) region is $3.50 per million calls ($14 total) plus data transfer fees of $0.09/GB ($1.08 in total for 12 GB). The total cost is $15.08.

Example #2: A private API in US East 

The API gets five million API calls, with requests averaging 0.3 KB and responses averaging 3 KB. You provision a VPC endpoint in the US East AZ for 720 hours (one month). In addition to the API call charges ($17.50), there are VPC endpoint charges of $7.20 ($0.01 per hour), Amazon VPC charges, and data processing fees. The total cost is $24.86.

WebSocket APIs

Example: Chat application

Five hundred users connect to the application for 12 hours daily, each sending 50 messages and receiving 200 messages on average (3,750,000 total over a month). Based on pricing for the US East AZ, the messaging costs will be $3.75 ($1 per million). The connectivity costs will be $2.70, based on the $0.25/million charge for 10.8 million connection minutes. The total cost will be $6.45.

5 tips for Amazon API Gateway cost optimization

1. Choosing the right type of API Gateway

One of the best ways to optimize API gateway costs is to choose the most cost-effective type of gateway. AWS provides two main options—REST and HTTP APIs. The HTTP API is more limited in functionality, but also cheaper. If this API gateway suits your needs, using it can save substantially on service costs.

2. API Gateway integration feature

Another way to reduce your API Gateway costs is to use the AWS Service Proxy integration, instead of binding your Lambda function to pass or transform the input data directly from the client. You can leverage the API Gateway integration feature to integrate Amazon API Gateway with other AWS services like Kinesis, SQS, SNS, and DynamoDB.

3. Cognito authentication

If the frontend is the only consumer of your backend API, you can use Cognito to retrieve the user’s IAM credentials. You can then use the AWS Javascript SDK and temporary credentials to safely invoke a Lambda function. This approach lets you implement authentication and authorization using IAM, eliminating the need for an API gateway. However, it provides reduced functionality —requests need to be prepared on the front end and responses and errors need to be handled in the Lambda code.

4. API Gateway with Application Load Balancer (ALB)

When you scale your application, you might need to replace the API gateway with an ALB. ALB supports the triggering of Lambda functions, so unless you are using specific features of Amazon API Gateway such as caching, authentication management, or request/response transformations, ALB may be a more cost-effective option.

5. Reduce data transfer costs

Standard data transfer rates ($0.09 per GB) apply when transferring data from your API Gateway to the public internet.

Using a content delivery network (CDN) like Amazon CloudFront is critical to keeping your data delivery costs low. CloudFront moves the most-visited content to the front end of your AWS network—to the point of presence (PoP) nearest to end users. Data transfer from different AWS resources like S3, EC2, and API Gateway to CloudFront is free.

Reducing API Gateway costs in AWS with Solo Gloo Gateway

Many companies choose to use Solo.io Gloo Gateway in place of AWS API Gateway for several reasons:

  • Ability to reduce costs due to AWS API-GW charging based on # of API Calls + Cache Memory vs. Solo API-Gateway charging based on # of clusters
  • Ability of Solo API-Gateway to be deployed in AWS or non-AWS environments
  • Ability of Solo API-Gateway to more tightly integrate with Kubernetes environments, both in AWS and outside AWS 

Learn more about Solo API-Gateway.

BACK TO TOP