# Buggy code
def get_user_managed_policy_data(boto3_session, user_list):
    resource_client = boto3_session.resource("iam")
    policies = {}
    for user in user_list:
        name = user["UserName"]
        arn = user["Arn"]
        resource_user = resource_client.User(name)
        policies[arn] = {
            p.policy_name: p.default_version.document["Statement"]
            for p in resource_user.attached_policies.all()
        }
    return policies


# Traceback (botocore.errorfactory.NoSuchEntityException)
Traceback (most recent call last):
File "/usr/local/bin/cartography", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.7/site-packages/cartography/cli.py", line 308, in main
return CLI(default_sync, prog='cartography').main(argv)
File "/usr/local/lib/python3.7/site-packages/cartography/cli.py", line 288, in main
return cartography.sync.run_with_config(self.sync, config)
File "/usr/local/lib/python3.7/site-packages/cartography/sync.py", line 145, in run_with_config
return sync.run(neo4j_driver, config)
File "/usr/local/lib/python3.7/site-packages/cartography/sync.py", line 71, in run
stage_func(neo4j_session, config)
File "/usr/local/lib/python3.7/site-packages/cartography/util.py", line 58, in timed
return method(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/cartography/intel/aws/__init__.py", line 144, in start_aws_ingestion
_sync_multiple_accounts(neo4j_session, aws_accounts, config.update_tag, common_job_parameters)
File "/usr/local/lib/python3.7/site-packages/cartography/intel/aws/__init__.py", line 92, in _sync_multiple_accounts
_sync_one_account(neo4j_session, boto3_session, account_id, sync_tag, common_job_parameters)
File "/usr/local/lib/python3.7/site-packages/cartography/intel/aws/__init__.py", line 25, in _sync_one_account
iam.sync(neo4j_session, boto3_session, account_id, sync_tag, common_job_parameters)
File "/usr/local/lib/python3.7/site-packages/cartography/util.py", line 58, in timed
return method(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/cartography/intel/aws/iam.py", line 623, in sync
sync_users(neo4j_session, boto3_session, account_id, update_tag, common_job_parameters)
File "/usr/local/lib/python3.7/site-packages/cartography/util.py", line 58, in timed
return method(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/cartography/intel/aws/iam.py", line 515, in sync_users
sync_user_inline_policies(boto3_session, data, neo4j_session, aws_update_tag)
File "/usr/local/lib/python3.7/site-packages/cartography/util.py", line 58, in timed
return method(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/cartography/intel/aws/iam.py", line 531, in sync_user_inline_policies
policy_data = get_user_policy_data(boto3_session, data['Users'])
File "/usr/local/lib/python3.7/site-packages/cartography/util.py", line 58, in timed
return method(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/cartography/intel/aws/iam.py", line 83, in get_user_policy_data
policies[arn] = {p.name: p.policy_document["Statement"] for p in resource_user.policies.all()}
File "/usr/local/lib/python3.7/site-packages/cartography/intel/aws/iam.py", line 83, in <dictcomp>
policies[arn] = {p.name: p.policy_document["Statement"] for p in resource_user.policies.all()}
File "/usr/local/lib/python3.7/site-packages/boto3/resources/collection.py", line 83, in __iter__
for page in self.pages():
File "/usr/local/lib/python3.7/site-packages/boto3/resources/collection.py", line 166, in pages
for page in pages:
File "/usr/local/lib/python3.7/site-packages/botocore/paginate.py", line 255, in __iter__
response = self._make_request(current_kwargs)
File "/usr/local/lib/python3.7/site-packages/botocore/paginate.py", line 332, in _make_request
return self._method(**current_kwargs)
File "/usr/local/lib/python3.7/site-packages/botocore/client.py", line 316, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python3.7/site-packages/botocore/client.py", line 635, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.errorfactory.NoSuchEntityException: An error occurred (NoSuchEntity) when calling the ListUserPolicies operation: The user with name <SANITIZED_USERNAME> cannot be found.

# Fixed code
def get_user_managed_policy_data(boto3_session, user_list):
    resource_client = boto3_session.resource("iam")
    policies = {}
    for user in user_list:
        name = user["UserName"]
        arn = user["Arn"]
        resource_user = resource_client.User(name)
        try:
            policies[arn] = {
                p.policy_name: p.default_version.document["Statement"]
                for p in resource_user.attached_policies.all()
            }
        except resource_client.meta.client.exceptions.NoSuchEntityException:
            logger.warning(
                f"Could not get policies for user {name} due to NoSuchEntityException; skipping.",
            )
    return policies