Python SDK Documentation #8553
-
Hey, most of the documentation that I have seen for c7 is all for the CLI tool but I am struggling to find anything for the Python SDK. Any help would be appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 2 replies
-
Custodian is intended and documented for CLI use, so there is no stable/documented library usage (see also #191). Depending on the "why" behind your question, invoking the CLI from Python might still be useful. For example: import c7n.cli
c7n.cli.main(['--help'])
c7n.cli.main(['run', '-s', '/my/output/dir/', '-vd', '/path/to/my/policy.yml']) ...but that's only useful if your goal is "running from Python". For the higher level discussion of library usage, #191 is the best context I'm aware of. |
Beta Was this translation helpful? Give feedback.
-
Ah, fair enough you're already in the hole! If you're going down to that level you'll probably find it useful to look at tests and other internals then. For example, you can follow breadcrumbs from here to see how the AWS provider does some magic behind the scenes to expand regions and reuse sessions. As for suppressing output, Custodian does have a null output but as far as I know it's only used/intended for internal testing. You could give that a shot following examples in the tests (you'll notice most tests call |
Beta Was this translation helpful? Give feedback.
-
That first snippet of code is exactly what I needed, thank you! |
Beta Was this translation helpful? Give feedback.
-
Another shot in the dark here. We are querying a number of resources for a handful of different accounts. EC2, S3, IAM stuff etc. 99% of the time everything is working as expected but for some random resources (auto scaling group, ecs task definition) they are not being returned even though we are confirmed to have them existing in the account Any thoughts on this? Some weird caching maybe? I'm sure this is a user error but wanted to just double check |
Beta Was this translation helpful? Give feedback.
-
hey @ajkerrigan back again, quick question if you had any insight into the error below. This is occurring when running a collection against
|
Beta Was this translation helpful? Give feedback.
-
Hmm that looks like a classic load balancer ARN that's missing the account ID piece... do you see the same error running the policy from the CLI? Not sure if somewhere along the line you're either not seeing an account ID or if something else is going on that's tripping up generate_arn (which gets called because |
Beta Was this translation helpful? Give feedback.
-
please note, custodian does not have a stable python interface, so this may break at any time. the cli and policy language is what we focus on for compatibility. we have at least one major upheaval coming with the move to c7n_core that will likely break the code samples in this discussion. |
Beta Was this translation helpful? Give feedback.
please note, custodian does not have a stable python interface, so this may break at any time. the cli and policy language is what we focus on for compatibility.
we have at least one major upheaval coming with the move to c7n_core that will likely break the code samples in this discussion.