Skip to content

(AccessDenied) when calling the AssumeRole operation #984

Closed

Description

@tenbasetom

Describe the bug
Upon running the script below, I got this error:

Traceback (most recent call last):
  File "/path/to/project/lib/python3.8/site-packages/cachetools/__init__.py", line 68, in __getitem__
    return self.__data[key]
KeyError: 'role_d628c45d0b65e289e3bc9ec298d1c7c0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/path/to/project/lib/python3.8/site-packages/sp_api/base/client.py", line 112, in role
    role = role_cache[cache_key]
  File "/path/to/project/lib/python3.8/site-packages/cachetools/__init__.py", line 418, in __getitem__
    return cache_getitem(self, key)
  File "/path/to/project/lib/python3.8/site-packages/cachetools/__init__.py", line 70, in __getitem__
    return self.__missing__(key)
  File "/path/to/project/lib/python3.8/site-packages/cachetools/__init__.py", line 97, in __missing__
    raise KeyError(key)
KeyError: 'role_d628c45d0b65e289e3bc9ec298d1c7c0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 14, in <module>
    order = order_client.get_order('113-4849434-1328255')
  File "/path/to/project/lib/python3.8/site-packages/sp_api/base/helpers.py", line 21, in wrapper
    return function(*args, **kwargs)
  File "/path/to/project/lib/python3.8/site-packages/sp_api/api/orders/orders.py", line 95, in get_order
    return self._request(fill_query_params(kwargs.pop('path'), order_id), params={**kwargs}, add_marketplace=False)
  File "/path/to/project/lib/python3.8/site-packages/sp_api/base/client.py", line 153, in _request
    auth=self._sign_request(),
  File "/path/to/project/lib/python3.8/site-packages/sp_api/base/client.py", line 122, in _sign_request
    role = self.role
  File "/path/to/project/lib/python3.8/site-packages/sp_api/base/client.py", line 114, in role
    role = self.set_role(cache_key)
  File "/path/to/project/lib/python3.8/site-packages/sp_api/base/client.py", line 81, in set_role
    role = self.boto3_client.assume_role(
  File "/path/to/project/lib/python3.8/site-packages/botocore/client.py", line 530, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/path/to/project/lib/python3.8/site-packages/botocore/client.py", line 960, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (AccessDenied) when calling the AssumeRole operation: Roles may not be assumed by root accounts.

test.py

from sp_api.base import Marketplaces
from sp_api.api import Orders

credentials = dict( ... )

order_client = Orders(credentials=credentials)
order = order_client.get_order('...')
print(order)

To Reproduce

Steps to reproduce the behavior:

  1. Follow steps 1-5 at https://developer-docs.amazon.com/sp-api/docs/creating-and-configuring-iam-policies-and-entities
  2. Create test.py (see code above)
  3. Execute python test.py

Expected behavior

I expected to see a printout of the order data.

Desktop (please complete the following information):

  • OS: Linux (Ubuntu 20.04.3)

Additional context

Python 3.8.10

Activity

  1. Repository owner locked and limited conversation to collaborators on Apr 2, 2023
  2. converted this issue into a discussion #985 on Apr 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions