-
Notifications
You must be signed in to change notification settings - Fork 397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] self.paginated_response
does not return the aggregated list of distributions (cloudfront_info)
#769
Comments
Files identified in the description:
If these files are inaccurate, please update the |
An ugly-yet-simple fix would be: # Only necessary until https://github.com/ansible-collections/community.aws/issues/769 gets fixed
def paginated_response(self, func, result_key=""):
'''
Returns expanded response for paginated operations.
The 'result_key' is used to define the concatenated results that are combined from each paginated response.
'''
args = dict()
results = dict()
items = []
loop = True
while loop:
response = func(**args)
if result_key == "":
result = response
result.pop('ResponseMetadata', None)
else:
result = response.get(result_key)
results.update(result)
if 'Items' in result.keys():
items = items + result.get('Items')
results['Items'] = items
args['Marker'] = response.get('NextMarker')
for key in response.keys():
if key.endswith('List'):
args['Marker'] = response[key].get('NextMarker')
break
loop = args['Marker'] is not None
return results |
There's actually a simpler option: boto3 has paginator helpers (only for some calls) You can see an example of how to use them in #472 : Would you be interested in submitting a Pull Request? Mark |
While my problem is purely on the distribution listing, it may also occur on any of the calls to
The method community.aws/plugins/modules/cloudfront_info.py Lines 459 to 472 in 3ae2b3e
Switching to boto3 iterators implies adjusting all the above calls, and I would rather wait for an experienced maintainer to carry out that task safely :) |
Fix cloudfront_info pagination bug SUMMARY Currently the cloudfront_info module is using a bespoke paginator function, which is causing some issues when over 100 distributions exist (see linked issue), when in fact it can be easily switched to a native boto3 paginator that would fix the bug reported in the linked issue. Fixes #769 ISSUE TYPE Bugfix Pull Request COMPONENT NAME cloudfront_info ADDITIONAL INFORMATION Pagination docs: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cloudfront.html#paginators Tests following steps from linked issue: ran a ansible task: - hosts: localhost connection: local gather_facts: false tasks: - name: "Check if distribution already exists" cloudfront_info: distribution: true domain_name_alias: "XX" register: distribution_data Results: TASK [Check if distribution already exists] ************************************************************************************************************************************************************************************************************************************ task path: /root/test/test.yml:6 <127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root <127.0.0.1> EXEC /bin/sh -c 'echo ~root && sleep 0' <127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1635164453.7083595-389-139483031845166 `" && echo ansible-tmp-1635164453.7083595-389-139483031845166="` echo /root/.ansible/tmp/ansible-tmp-1635164453.7083595-389-139483031845166 `" ) && sleep 0' Using module file /root/test/library/cloudfront_info.py <127.0.0.1> PUT /root/.ansible/tmp/ansible-local-3861wn9tjv7/tmp6o0jv2s2 TO /root/.ansible/tmp/ansible-tmp-1635164453.7083595-389-139483031845166/AnsiballZ_cloudfront_info.py <127.0.0.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1635164453.7083595-389-139483031845166/ /root/.ansible/tmp/ansible-tmp-1635164453.7083595-389-139483031845166/AnsiballZ_cloudfront_info.py && sleep 0' <127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1635164453.7083595-389-139483031845166/AnsiballZ_cloudfront_info.py && sleep 0' <127.0.0.1> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1635164453.7083595-389-139483031845166/ > /dev/null 2>&1 && sleep 0' ok: [localhost] => { "changed": false, "cloudfront": { "XXXXXX": { "Distribution": { "ARN": "arn:aws:cloudfront::XXXXXXXX:distribution/XXXXXX", "ActiveTrustedKeyGroups": { "Enabled": false, "Quantity": 0 }, "ActiveTrustedSigners": { "Enabled": false, "Quantity": 0 }, "AliasICPRecordals": [ { "CNAME": "XXXX", "ICPRecordalStatus": "APPROVED" } ], ... Reviewed-by: Mark Chappell <None> Reviewed-by: Mark Woolley <[email protected]> Reviewed-by: Markus Bergholz <[email protected]> Reviewed-by: None <None>
…ns#769) Update changelog (main branch) with the amazon.aws 3.2.0 changes SUMMARY Update changelog (main branch) with the amazon.aws 3.2.0 changes ISSUE TYPE Docs Pull Request Reviewed-by: Mark Chappell <None> Reviewed-by: Markus Bergholz <[email protected]>
Summary
AWS paginates distributions by default at 100 items per page.
Trying the following can cause an error if the distribution appears in the first page of the results:
The error lies at the line 502, in the function
paginated_response
:community.aws/plugins/modules/cloudfront_info.py
Line 502 in 3ae2b3e
For distributions, AWS returns an object as follows:
Which means
results.update(result)
on the Nth page overwrites the previous results, causing the returned data to only include the distributions included in the last page -- as theitems
arrays are not concatenated togetherIn my case the 2nd page shows the following object:
And printing the length of results returned by
service_mgr.get_distribution_id_from_domain_name(domain_name_alias)
yields59
, which is incorrect, and should be 159 as can be seen from the following screenshotIssue Type
Bug Report
Component Name
cloudfront_info
Ansible Version
Collection Versions
The bug exists in both
cloudfront_unfo
taken directly from https://github.com/ansible-collections/community.aws/blob/3ae2b3efa4588ac1284c565d6f73543a555a5edd/plugins/modules/cloudfront_info.py (3ae2b3e being the latest as of the this writing)AWS SDK versions
Configuration
OS / Environment
Debian 4.19.194-3 (2021-07-18) x86_64
Steps to Reproduce
Sample fetch:
Expected Results
EXPECTATIONS:
Actual Results
Thrown by:
community.aws/plugins/modules/cloudfront_info.py
Lines 607 to 611 in 3ae2b3e
Code of Conduct
The text was updated successfully, but these errors were encountered: