Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion samtranslator/translator/managed_policy_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ class ManagedPolicyLoader(object):
def __init__(self, iam_client):
self._iam_client = iam_client
self._policy_map = None
self.max_items = 1000

def load(self):
if self._policy_map is None:
LOG.info("Loading policies from IAM...")

paginator = self._iam_client.get_paginator("list_policies")
# Setting the scope to AWS limits the returned values to only AWS Managed Policies and will
# not returned policies owned by any specific account.
# http://docs.aws.amazon.com/IAM/latest/APIReference/API_ListPolicies.html#API_ListPolicies_RequestParameters
page_iterator = paginator.paginate(Scope="AWS")
# Note(jfuss): boto3 PaginationConfig MaxItems does not control the number of items returned from the API
# call. This is actually controlled by PageSize.
page_iterator = paginator.paginate(Scope="AWS", PaginationConfig={"PageSize": self.max_items})
name_to_arn_map = {}

for page in page_iterator:
Expand Down
2 changes: 1 addition & 1 deletion tests/translator/test_managed_policies_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ def test_load():
assert actual == expected

iam.get_paginator.assert_called_once_with("list_policies")
paginator.paginate.assert_called_once_with(Scope="AWS")
paginator.paginate.assert_called_once_with(Scope="AWS", PaginationConfig={"PageSize": 1000})