Selling Partner API BlogVideos
SP-API DocsDeveloper ConsoleSupport
SP-API DocsDeveloper ConsoleSupport

Monitor SP-API throttling with CloudWatch

This blog post describes how to monitor SP-API throttling using CloudWatch.

by Jiang G., Solutions Architect, Selling Partner Developer Services | October 30, 2023

Amazon Selling Partner API (SP-API) is a critical component for many business owners, providing seamless integration with Amazon's vast marketplace. However, managing and monitoring API calls can be a complex task, especially when handling throttling and ensuring efficient resource management.

This blog introduces the importance of monitoring API throttling and a sample solution using AWS CloudWatch.

Background

Amazon has implemented usage plans and rate limits. Each usage plan consists of a rate and a burst. The rate defines the number of requests per second that can be added to the token bucket without experiencing throttling. Staying below this rate can protect end users from unexpected application errors. The burst limits the maximum token bucket size. With a token bucket, users can build up requests and submit them simultaneously. It's essential to note that these usage limits are specific to each seller and region. For more information, refer to Overview of usage plans and rate limits.

The importance of handling throttling

Since you, as a developer, need to adhere to the rate limit and burst, throttling has become important when using SP-API. API throttling is a mechanism that controls the amount of requests an application can submit within a specified time frame. By enforcing rate limits, Amazon can maintain the health and efficiency of SP-API usage. Handling API throttling appropriately ensures fair usage and maintains a quality experience for all users. Amazon manages the frequency of requests to protect against service disruptions during peak usage times. For more information, refer to Strategies to optimize rate limits for your application workloads.

One of the best ways to manage throttling is to monitor API activity.

Monitoring

API monitoring is not just checking if an API is up or down. It's about understanding how your API behaves in the real world. Monitoring provides insight into the performance, availability, and functional correctness of APIs. It helps in early detection of issues, ensuring that the services dependent on the API don't face disruptions.

One solution is to use Amazon CloudWatch, which is a monitoring and observability service offered by AWS. It provides data and actionable insights for AWS, hybrid, and on-premises applications and infrastructure resources. With CloudWatch, you can set up alarms based on specific metrics, such as the number of throttled requests. By monitoring these metrics, you can get real-time feedback and take corrective actions if they notice an unusual spike in throttled requests. By leveraging AWS's infrastructure, you can set up alarms, monitor API call patterns, and get real-time feedback on their API's health. This proactive approach ensures that any potential issues are identified and addressed promptly, ensuring smooth operations.

The SP-API Throttling Monitor Workshop is a comprehensive guide that provides step-by-step instructions to deploy a Python Lambda backend that makes API calls to SP-API in an AWS environment. This workshop is designed to equip users with hands-on experience in setting up a throttling monitor for SP-API using AWS CloudWatch and related services. It covers the detailed operations of the below key aspects:

  1. CloudFormation setup: AWS CloudFormation provides a common language for you to describe and provision the infrastructure resources in your cloud environment. With CloudFormation you can use a simple text file to model and provision the resources needed for your applications in an automated and secure manner. The benefits include increased speed and consistency of deployments, simplified infrastructure management, and the ability to use version control for your infrastructure.

  2. Lambda function setup: AWS Lambda is a serverless, event-driven compute service that runs your code in response to events and automatically manages the underlying compute resources for you. With Lambda, you can run code without provisioning or managing servers, and scale automatically with the size of the workload. The benefits include reduced operational complexity, cost efficiency, and the ability to focus on core business logic.

  3. Invoking the Lambda function: A Python script (lambda_invoker.py) is provided to invoke the Lambda function and simulate SP-API calls, so users can control the API call pattern. Invoking the Lambda function is essential to test the functionality and simulate real-world scenarios. This helps with understanding how the function interacts with other AWS services, simulating SP-API calls, and ensuring that the entire setup works as intended.

  4. CloudWatch alarms: With CloudWatch alarms you can monitor Amazon CloudWatch metrics over a specified time period and perform one or more actions based on the value of a metric relative to a threshold over time. The benefits include real-time monitoring, automated responses to changes, and the ability to diagnose issues quickly.

  5. CloudWatch Logs Insights: With CloudWatch Logs Insights you can explore, analyze, and visualize your logs instantly. It provides an interactive query capability, so you can understand the operational health and performance of your systems. The benefits include faster troubleshooting, improved security monitoring, and enhanced operational efficiency.

  6. Email notifications: Email notifications act as an immediate alert system, keeping stakeholders informed and facilitating quick response to any issues. The benefits include a timely awareness of critical events, streamlined communication, and enhanced incident management.

The SP-API Throttling Monitor Workshop is a valuable resource for anyone looking to enhance the reliability and performance of their SP-API application. By completing this workshop, you can gain practical insights into efficient resource management and smooth operations.

Conclusion

Monitoring plays a critical part when using any API. Amazon provides great experience with its usage plans and rate limits. However, these limits also bring forth the challenge of throttling. As a developer, it is imperative for you to understand and manage API requests to avoid potential disruptions. With tools like AWS CloudWatch, managing and monitoring SP-API calls has become more straightforward. By leveraging these tools and adhering to best practices, you can ensure that applications run smoothly, providing users with a seamless and efficient experience. With the increasing complexity of digital ecosystems, having a comprehensive API monitoring strategy is crucial to ensure seamless integrations and interactions between services.

👍

Have feedback on this post?

If you have questions or feedback on this post, we'd like to hear from you! Please vote and leave a comment using the tools at the bottom of this page.

Subscribe to updates via RSS feed.