newbie - how to list ec2 instances

352 views
Skip to first unread message

lightbeard

unread,
Mar 21, 2017, 10:19:21 AM3/21/17
to cloud-custodian
We are very impressed with the capability and flexibility of cloud-custodian.

Right now, I'm just trying to get started. I thought a good first policy would be to list running EC2 instances, but haven't been successful:

test.yml

policies:
  - name: list-running-ec2
    resource: ec2
    filters:
      - "instance-state-name": running


[ec2-user@ip-10-97-13-39]$ custodian run test.yml -s . --dryrun -v
2017-03-21 14:10:18,186: custodian.cli:DEBUG using default region:us-east-1 from boto
2017-03-21 14:10:18,253: custodian.commands:DEBUG Loaded file test.yml. Contains 1 policies (after filtering)
2017-03-21 14:10:18,254: custodian.output:DEBUG Storing output with <DirectoryOutput to dir:./list-running-ec2>
2017-03-21 14:10:18,254: custodian.policy:INFO Running policy list-running-ec2 resource: ec2 region:us-east-1 c7n:0.8.23.2

Is it normal for the process to hang here? It doesn't seem to return so I exit with Cntr-C.

[ec2-user@ip-10-97-13-39]$ cat list-running-ec2/custodian-run.log
2017-03-21 14:10:18,254 - custodian.policy - INFO - Running policy list-running-ec2 resource: ec2 region:us-east-1 c7n:0.8.23.2

Do I need to specify an action to list the ec2 instance names? The documentation seems to suggest that the --dryrun flag will list AWS Resources.

Mandeep Bal

unread,
Mar 21, 2017, 1:03:56 PM3/21/17
to lightbeard, cloud-custodian
Hi,

My first thoughts are you might be running behind a proxy but have you tried the query with the filters? So just have resource: ec2
--
You received this message because you are subscribed to the Google Groups "cloud-custodian" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cloud-custodi...@googlegroups.com.
To post to this group, send email to cloud-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cloud-custodian/af1fc664-30ab-4269-84a1-07b2b99bfdc4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

lightbeard

unread,
Mar 21, 2017, 2:04:36 PM3/21/17
to cloud-custodian
Thanks for the suggestion, but I got the same output with the following policy.

policies:
  - name: list-running-ec2
    resource: ec2

I've setup cloud-custodian on an EC2 instance within AWS - so I'm not aware of a proxy, but perhaps I need to change its security group or IAM role?

lightbeard

unread,
Mar 21, 2017, 2:31:13 PM3/21/17
to cloud-custodian
I figured it out. There was a security group on the cloud-custodian instance I setup that was restricting outbound traffic - I noticed then when even the AWS CLI was not working. When I relaxed the outbound rules for all HTTP/HTTPS it worked

Kapil Thangavelu

unread,
Apr 17, 2017, 11:46:02 AM4/17/17
to cloud-custodian
filters:
   - State.Name: running


instance-state-name is for a server side `query`
Reply all
Reply to author
Forward
0 new messages