question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Document how to catch a ProvisionedThroughputExceededException

See original GitHub issue

The documentation makes explicit references to a ProvisionedThroughputExceededException:

If a PutRecord request cannot be processed because of insufficient provisioned throughput on the shard involved in the request, PutRecord throws ProvisionedThroughputExceededException .

The link is broken, and there’s no information on how to catch this exception. Furthermore, grepping the source code for boto3 and botocore only turns up documentation references to ProvisionedThroughputExceededException, no actual implementations of it, so I’m unsure what to import to try and catch/handle this exception.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:8
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

18reactions
ademiduncommented, May 14, 2018

This gist might be useful. h/t @shentonfreude

from botocore.exceptions import ClientError

RETRY_EXCEPTIONS = ('ProvisionedThroughputExceededException',
                    'ThrottlingException')
retries=0
while True:
    try:
        res = table.scan(**scan_kw)
        popular.extend(res['Items'])
        last_key = res.get('LastEvaluatedKey')
        print('len={} res[Count]={} last_key={}'.format(
            len(popular), res['Count'], last_key))
        if not last_key:
            break
        retries = 0          # if successful, reset count
        scan_kw.update({'ExclusiveStartKey': last_key})
    except ClientError as err:
        if err.response['Error']['Code'] not in RETRY_EXCEPTIONS:
            raise
        print('WHOA, too fast, slow it down retries={}'.format(retries))
        sleep(2 ** retries)
        retries += 1     # TODO max limit
10reactions
alexwlchancommented, Aug 22, 2017

If I could reliably reproduce this, I could just print out the properties of a ClientError and figure out how to check it for a ProvisionedThroughputExceededException, but it’s not really trivial to reproduce this error.

I was able to reproduce this by flooding a table with capacity=1 with write requests and capturing the error object. For future reference, here are what I think are likely the interesting bits:

import pprint
import random

import boto3

dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('test__alex')
while True:
    try:
        table.put_item(Item={'ID': str(random.randint(1, 100000)), 'name': open('/usr/share/dict/words').read(2048)})
    except Exception as e:
        f = e
        break

error = f
for attr in dir(f):
    if attr.startswith('_'):
        continue
    print(attr)
    pprint.pprint(getattr(f, attr))
    print()
MSG_TEMPLATE
('An error occurred ({error_code}) when calling the {operation_name} '
 'operation{retry_info}: {error_message}')

args
('An error occurred (ProvisionedThroughputExceededException) when calling the '
 'PutItem operation (reached max retries: 9): The level of configured '
 'provisioned throughput for the table was exceeded. Consider increasing your '
 'provisioning level with the UpdateTable API.',)

operation_name
'PutItem'

response
{'Error': {'Code': 'ProvisionedThroughputExceededException',
           'Message': 'The level of configured provisioned throughput for the '
                      'table was exceeded. Consider increasing your '
                      'provisioning level with the UpdateTable API.'},
 'ResponseMetadata': {'HTTPHeaders': {'connection': 'keep-alive',
                                      'content-length': '241',
                                      'content-type': 'application/x-amz-json-1.0',
                                      'date': 'Tue, 22 Aug 2017 10:04:59 GMT',
                                      'server': 'Server',
                                      'x-amz-crc32': '1545824508',
                                      'x-amzn-requestid': 'CDRKT1L3H717RM1CL61P5J1L63VV4KQNSO5AEMVJF66Q9ASUAAJG'},
                      'HTTPStatusCode': 400,
                      'MaxAttemptsReached': True,
                      'RequestId': 'CDRKT1L3H717RM1CL61P5J1L63VV4KQNSO5AEMVJF66Q9ASUAAJG',
                      'RetryAttempts': 9}}

with_traceback
<built-in method with_traceback of ProvisionedThroughputExceededException object at 0x10f72b588>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error handling with DynamoDB - AWS Documentation
Discover the best practices for handling client and server errors and exceptions returned by Amazon DynamoDB operations.
Read more >
Getting ProvisionedThroughputExceededException error ...
The read provisioned throughput is set to 1000 so it should be enough. The write provisioned t/p was set to a low value...
Read more >
Developers - Document how to catch a ... - Bountysource
The documentation makes explicit references to a ProvisionedThroughputExceededException: If a PutRecord request cannot be processed because of ...
Read more >
ProvisionedThroughputExceede...
DocumentationProvisionedThroughputExceededException ... The request rate for the stream is too high, or the requested data is too large for the available ...
Read more >
Textract Throttling | AWS re:Post
So I just had my get document text increased to 35 but they kept ... I still get: An error occurred (ProvisionedThroughputExceededException) when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found