13 Strategies for Reducing Your Cloud Spend on AWS API Gateway
Before we dive into cost reduction, let’s Understand API Gateway Pricing Model: With the API Gateway, you pay only when your APIs are in use.
Here are the main highlights of the pricing model:
- The free tier is available for 12 months.
- You get 1 million REST and HTTP API calls for free.
- The first 1 million messages and 750,000 connection minutes are free as well.
- HTTP API charges based on call count (512 KB increments).
- WebSocket API charges for message connection minutes.
- Cache pricing depends on provisioned memory.
- Additional charges for Data Transfer, CloudWatch, and other services.
Now, let’s get to the business:
- Right type of API gateway: AWS offers both REST APIs and HTTP APIs. The HTTP API has more limited functionality but is also much cheaper.
- API Gateway integration feature: use AWS service proxy integrations instead of combining a Lambda function to transfer/transform input data from the client. You can integrate API Gateway with other AWS services directly (e.g. Kinesis, DynamoDB, SQS, SNS, etc.) by using?API Gateway integration features.
- Cognito authentication: When your front-end is the only consumer of the backend APIs, you can leverage Cognito to obtain IAM credentials for your users. They can then invoke your Lambda functions safely using the AWS JavaScript SDK and the temporary credentials. This solution allows you to achieve both authentication and authorization via IAM,?avoiding the need for an API Gateway?at the cost of reduced functionalities.
- Replace API Gateway with ALB (Application Load Balancer): As your application scales, consider replacing the API Gateway with an?ALB (Application Load Balancer). Since ALB supports triggering the Lambda function, ALB could be a better choice for cost savings unless you’re using Amazon API Gateway’s unique features, such as authentication management, caching, and request/response transformation.
- Reduce unnecessary API calls: Remove any unnecessary API calls and optimize your application to prevent them.
- Implement usage plans: API Gateway's usage plans allow you to control access to your APIs and associate usage quotas and throttling limits. By implementing tiered usage plans, you can charge higher-volume consumers more, incentivizing them to optimize their API usage.
- Leverage Lambda@Edge: For APIs that require low latency responses, consider using Lambda@Edge to execute your API logic at the edge, closer to your users. This will reduce the number of API calls to your central API Gateway.
- Monitor and optimize continuously: Identify high-cost APIs, optimize their configurations, and automate cost-saving measures where possible.
- Leverage AWS Lambda integrations: When possible, integrate your APIs directly with AWS Lambda functions instead of proxying through API Gateway. This can reduce the number of API Gateway requests and associated costs.
- Implement API versioning: Regularly review your API versions and deprecate older versions that are no longer in use.
- Leverage AWS WAF: Use AWS Web Application Firewall (WAF) to protect your APIs from malicious traffic and bots.
- Optimize API caching: Take advantage of API Gateway's caching capabilities to reduce the number of calls to your backend services. Carefully configure your cache settings to balance cost savings and data freshness.
- Use AWS Service Proxy Integrations: use the proxy integrations instead of Lambda functions for data transformations. It directly integrates the Gateway with other services, including Lambda and Kinesis. It eliminates the need for custom code for APIs and reduces the number of data transfer requests.
Cloud Software Engineer at Mobileye
4 个月Interesting indeed But I am not sure about your 4th As alb has cost to maintain itself while API gateway is priced per request 'only'