Issue
I think I have trouble understanding the boto3 documentation.
I basically want to retrieve a list of ActiveTrustedSigners
for each cloudfront distribution.
From the documentation here http://boto.cloudhackers.com/en/latest/ref/cloudfront.html#module-boto.cloudfront.signers I am aware of the class ActiveTrustedSigners.
However how can I retrieve it from a distribution?
Here is code
import boto
import os
from boto.cloudfront import CloudFrontConnection
def main():
KEY_ID = os.environ['CF_KEY_ID']
SECRET = os.environ['CF_SECRET']
cnn = CloudFrontConnection(KEY_ID, SECRET)
for dist in cnn.get_all_distributions():
print dist.ActiveTrustedSigners() # AttributeError: 'DistributionSummary' object has no attribute 'ActiveTrustedSigners'
I got an 'AttributeError' here. So how I can get from DistributionSummary
to a list of ActiveTrustedSigners
.
Solution
Turns out I can get the Distribution
object from DistributionSummary
, and then I can interrogate active_signers
from there.
Here is the final version
import os
from boto.cloudfront import CloudFrontConnection
def main():
KEY_ID = os.environ['CF_KEY_ID']
SECRET = os.environ['CF_SECRET']
cnn = CloudFrontConnection(KEY_ID, SECRET)
for dist_summary in cnn.get_all_distributions():
dist = dist_summary.get_distribution()
if dist.active_signers:
for signer in dist.active_signers:
print signer.key_pair_ids
if __name__ == '__main__':
main()
Answered By - Anthony Kong
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.