# Buggy code
def get_role_policy_data(boto3_session, role_list):
    resource_client = boto3_session.resource("iam")
    policies = {}
    for role in role_list:
        name = role["RoleName"]
        arn = role["Arn"]
        resource_role = resource_client.Role(name)
        policies[arn] = {
            p.name: p.policy_document["Statement"] for p in resource_role.policies.all()
        }
    return policies


# Traceback (botocore.errorfactory.NoSuchEntityException)
Traceback (most recent call last):
File "{PATH}/intelmodules/syncgraph.py", line 220, in <module>
main(argv)
File "{PATH}/intelmodules/syncgraph.py", line 210, in main
return cartography.sync.run_with_config(sync, config)
File "/lib/python3.6/site-packages/cartography/sync.py", line 145, in run_with_config
return sync.run(neo4j_driver, config)
File "/lib/python3.6/site-packages/cartography/sync.py", line 71, in run
stage_func(neo4j_session, config)
File "{PATH}/intelmodules/lyft/aws.py", line 234, in lyft_start_aws_ingestion
common_job_parameters
File "/lib/python3.6/site-packages/cartography/intel/aws/__init__.py", line 96, in _sync_multiple_accounts
_sync_one_account(neo4j_session, boto3_session, account_id, sync_tag, common_job_parameters)
File "/lib/python3.6/site-packages/cartography/intel/aws/__init__.py", line 27, in _sync_one_account
iam.sync(neo4j_session, boto3_session, account_id, sync_tag, common_job_parameters)
File "/lib/python3.6/site-packages/cartography/util.py", line 58, in timed
result = method(*args, **kwargs)
File "/lib/python3.6/site-packages/cartography/intel/aws/iam.py", line 656, in sync
sync_roles(neo4j_session, boto3_session, account_id, update_tag, common_job_parameters)
File "/lib/python3.6/site-packages/cartography/util.py", line 58, in timed
result = method(*args, **kwargs)
File "/lib/python3.6/site-packages/cartography/intel/aws/iam.py", line 595, in sync_roles
sync_role_inline_policies(current_aws_account_id, boto3_session, data, neo4j_session, aws_update_tag)
File "/lib/python3.6/site-packages/cartography/intel/aws/iam.py", line 611, in sync_role_inline_policies
inline_policy_data = get_role_policy_data(boto3_session, data["Roles"])
File "/lib/python3.6/site-packages/cartography/util.py", line 58, in timed
result = method(*args, **kwargs)
File "/lib/python3.6/site-packages/cartography/intel/aws/iam.py", line 120, in get_role_policy_data
policies[arn] = {p.name: p.policy_document["Statement"] for p in resource_role.policies.all()}
File "/lib/python3.6/site-packages/cartography/intel/aws/iam.py", line 120, in <dictcomp>
policies[arn] = {p.name: p.policy_document["Statement"] for p in resource_role.policies.all()}
File "/lib/python3.6/site-packages/boto3/resources/collection.py", line 83, in __iter__
for page in self.pages():
File "/lib/python3.6/site-packages/boto3/resources/collection.py", line 166, in pages
for page in pages:
File "/lib/python3.6/site-packages/botocore/paginate.py", line 255, in __iter__
response = self._make_request(current_kwargs)
File "/lib/python3.6/site-packages/botocore/paginate.py", line 332, in _make_request
return self._method(**current_kwargs)
File "/lib/python3.6/site-packages/botocore/client.py", line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/lib/python3.6/site-packages/botocore/client.py", line 661, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.errorfactory.NoSuchEntityException: An error occurred (NoSuchEntity) when calling the ListRolePolicies operation: The role with name NAME_HERE cannot be found.

# Fixed code
def get_role_policy_data(boto3_session, role_list):
    resource_client = boto3_session.resource("iam")
    policies = {}
    for role in role_list:
        name = role["RoleName"]
        arn = role["Arn"]
        resource_role = resource_client.Role(name)
        try:
            policies[arn] = {
                p.name: p.policy_document["Statement"]
                for p in resource_role.policies.all()
            }
        except resource_client.meta.client.exceptions.NoSuchEntityException:
            logger.warning(
                f"Could not get policies for role {name} due to NoSuchEntityException; skipping.",
            )
    return policies