scopely-devops / skew

Apache License 2.0
242 stars 70 forks source link

Simple iteration not working for me #93

Closed mholtby closed 8 years ago

mholtby commented 8 years ago

import skew arn = skew.scan('arn:aws:ec2:::instance/') for instance in arn: ... print(arn) ... arn:aws:ec2:::instance/ arn:aws:ec2:::instance/ arn:aws:ec2:::instance/ arn:aws:ec2:::instance/ arn:aws:ec2:::instance/ arn:aws:ec2:::instance/ arn:aws:ec2:::instance/ arn:aws:ec2:::instance/*

When I use resource.data and explicitly choose an individual ARN it works fine and I get the results -

from skew import scan arn = skew.scan('arn:aws:ec2:eu-west-1:093228123150:instance/i-0fdffef58576f8027') Traceback (most recent call last): File "", line 1, in NameError: name 'skew' is not defined arn = scan('arn:aws:ec2:eu-west-1:XXXXXXXXXXX:instance/i-0fdfXXXXXXXX027') for resource in arn: ... print(resource.data) ... {u'Monitoring': {u'State': 'disabled'}, u'PublicDnsName': 'ec2-52-XX-139-XX.eu-west-1.compute.amazonaws.com', u'State': {u'Code': 16, u'Name': 'running'}, u'EbsOptimized': True, yada yada yada

My end goal is to pull ARNs for all AWS resources within an AWS Account. Trying to get the script at the bottom of the stackoverflow (http://stackoverflow.com/questions/30674938/how-to-progammatically-list-all-aws-resources-and-tags) working but that's not either.

Any help gratefully received!

inhumantsar commented 8 years ago

It looks like your loop at the top is working, it's just that the string representation of these objects is a little misleading IIRC. Have you tried printing an attribute of the obj rather than the obj as a whole? The block below works for me:

>>> import skew
>>> arn = skew.scan('arn:aws:ec2:::instance/')
>>> for i in arn:
...     print(i.data)
... 
{u'Monitoring': {u'State': 'disabled'}, u'PublicDnsName': '', u'State': {u'Code': 16, u'Name': 'running'}, u'EbsOptimized': False, u'LaunchTime': datetime.datetime(2016, 5, 30, 14, 30, 6, tzinfo=tzutc()), ...
garnaat commented 8 years ago

Your loop does not look correct. Perhaps it's just a typo but this should work for you:

import skew
arn = skew.scan('arn:aws:ec2:::instance/*')
for i in arn:
    print(i.arn)