0
votes

I am trying to keep a running total of data in 5 minutes increments. The logic I have is based on this tutorial:

Keeping running totals

I have a table set up and it is finished creating. It has the following keys:

Primary partition key timeStamp (String) Primary sort key thing (String)

There is no data in the table.

I am trying to following json to add/update. I am expecting that when boto3 tries to update the table if it does not find a record with the primary/secondary key values it will add one.

I am getting the following error:

An error occurred (ResourceNotFoundException) when calling the UpdateItem operation: Requested resource not found: ResourceNotFoundException Traceback (most recent call last): File "/var/task/lambda_function.py", line 44, in lambda_handler update_dynamo_event_counter('cycles.5.minutes', key1, key[0], int(val)) File "/var/task/lambda_function.py", line 15, in update_dynamo_event_counter 'thing': "a thing", File "/var/runtime/boto3/resources/factory.py", line 520, in do_action response = action(self, *args, **kwargs) File "/var/runtime/boto3/resources/action.py", line 83, in call response = getattr(parent.meta.client, operation_name)(**params) File "/var/runtime/botocore/client.py", line 312, in _api_call return self._make_api_call(operation_name, kwargs) File "/var/runtime/botocore/client.py", line 601, in _make_api_call raise error_class(parsed_response, operation_name) botocore.errorfactory.ResourceNotFoundException: An error occurred (ResourceNotFoundException) when calling the UpdateItem operation: Requested resource not found

This is my code:

def update_dynamo_event_counter(tableName, ts, t, event_count=1, dynamodb = boto3.resource(service_name='dynamodb', region_name='eu-west-1')):
        table = dynamodb.Table(tableName)
        hrTimeStamp = datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
        response = table.update_item(
        Key={
            'timeStamp': "123456", 
            'thing': "a thing",
            }
        )

I am passing the table name "theTable" and not the arn resource string.

1
Have you actually got the DynamoDB resource to perform table = dynamodb.Table(tableName).smcstewart

1 Answers

0
votes

I have faced the similar problem. Please check the in your code whether you have created the item properly or not. i.e., put_item or batch_item you are using in your code is not created or executing the put_item or batch_item when it is in creation stage.

Hold your execution until table is created properly and it is in "ACTIVE" state. and then execute the put_item or batch_item and check whether it is created or not.

Wait until the "ACTIVE STATE" after put_item or batch_item and then update the item using update_item.

Your error seems to be, you have not created the item properly using put_item or batch_item and trying to update the item when item itself is not executed properly.