ResourceNotFoundException when call Dynamo by a lib, but work when call via boto3 directly

0

Hello. I'm working on a PoC where I'm doing account B access Dynamo database from account A. It is properly configured following documentation from AWS. When I'm calling it directly with boto3 calls, it work.

response = dynamodb_client.get_item(TableName=table, Key={'partkey': {'S': register_key}, 'sortkey': {'S': sales_org}})

But since is a refactor, the previous structure uses a lib (DynamoRM(https://nerdwalletoss.github.io/dynamorm/)) to manage the requests to database (and it works in previous structure without cross data access), and since move to directly call to boto3 involve to refactor a bunch of logic and models, I wanna keep using the lib for now, until properly plan this second step. Using that (external lib) structure, it fails (in boto3 dependencies) to locate data that I can saw when use boto3.

Can someone have any idea why this could happen?

Below I share the error when calling boto3 client via lib:

[ERROR] ResourceNotFoundException: An error occurred (ResourceNotFoundException) when calling the GetItem operation: Requested resource not found
Traceback (most recent call last):
  File "/var/task/pylambdarest/route.py", line 119, in inner_func
    res = handler(**func_args_values)
  File "/var/task/src/app.py", line 89, in get_item_by_id
    response = DataServices(table, sortkey=sales_org,
  File "/var/task/src/dataservice.py", line 39, in _get_record
    record = DTable.get(partkey=self.partkey,
  File "/var/task/dynamorm/model.py", line 334, in get
    item = cls.Table.get(consistent=consistent, **kwargs)
  File "/var/task/dynamorm/table.py", line 772, in get
    response = self.table.get_item(**get_item_kwargs)
  File "/var/task/boto3/resources/factory.py", line 580, in do_action
    response = action(self, *args, **kwargs)
  File "/var/task/boto3/resources/action.py", line 88, in __call__
    response = getattr(parent.meta.client, operation_name)(*args, **params)
  File "/var/task/botocore/client.py", line 535, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/var/task/botocore/client.py", line 983, in _make_api_call
    raise error_class(parsed_response, operation_name)
END RequestId: d93eb01d-7552-474e-9d55-dea98a77d7a8
asked 5 months ago256 views
1 Answer
0

Repeating this back to you:

When using a third-party library, access to DynamoDB works when the call is within the same account but fails when it is cross account. However, boto3 works in both cases.

If that's the case you need to look at where you are using the cross-account credentials with the third-party library. Given that it is a third-party library I'd also check the support forums for that library.

profile pictureAWS
EXPERT
answered 5 months ago
  • Hello. In same account it works using the third-party lib (did not tested with boto3 since did not needed, and also my PoC is exactly to do cross account). I'm trying to have some guidance about the lib community, but looks is not much used these days (also idk why my team is using, I enter recently and it was being used since beginning and the people now did not know also). I know probably good approach is replace it for boto or another one, but since this have a bunch of logic and data models being used, just wanna do it in future (after PoC of cross account). For that reason I tried to, before use this third-part lib, set/override boto3 configurations (the same I have done when call boto3 directly), but it is not enough. Just asking here to see if can I maybe have another way to try force boto3 access, otherwise probably have to refactor that now, instead of do it in a next step.

  • There are several ways to specify which credentials that code uses; but I think that the key here is that you're talking about resources in a different account. So you either have credentials for that other account available; or the code has to assume a role in a different account which might be where the issue is.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions