PokaInc / arnparse

Parse ARNs using Python
MIT License
36 stars 7 forks source link

Generate ARNs in order to be able to get the right ones from cloudformation lists. #6

Open mikedlr opened 5 years ago

mikedlr commented 5 years ago

With cloudformation I can recover a list of resources created by each stack but the data about each resource does not include the ARN.

In order to be able to match resources to cloudformation stacks I would like to be able to be able to use arnparse to generate ARNs from the constituent data recovered from a cloudformation stack. See also the output of aws cloudformation list-stack-resources

I'd propose implementing a __str__ method which returns the ARN and a __repr__ method which returns an ARN instantiation call.

In fact I'm probably going to go ahead and do this, but I'd like to put up an issue to explain it first.

laurrentt commented 5 years ago

Hey @mikedlr, that sounds cool. However, for it to work it would require the code to gather your account id, current region and somehow find the service the resource belongs to. It would have to know all the corner cases regarding ARNs, like the fact that S3 buckets don't specify the region, etc. Would you input all those properties? or would you expect arnparse to make the appropriate boto3 calls to gather this information?

mikedlr commented 5 years ago

I think I'd normally provide the missing parameters since it's impossible to be sure what parameters were actually used during a call that created the JSON but I would provide a function like guess_aws_params which would use normal AWS credential resolution (arguments / environment / default credentials in .aws from environemnt / default in .aws) to fill in the rest on demand. Maybe a guess=true parmeter when creating the ARN object?

In my use case I would get an ARN for a cloudformation stack and then parse it and then call the cloudformation API call, so I would already know (from the original ARN) all the parameters I need. Also I will be scanning over all regions so I couldn't rely on the guess function.

mikedlr commented 5 years ago

@laurrentt further on the comment on the need to understand the structure of ARNs - that's precisely the reason I went looking for a library. My most important need is to be able to match against other ARNs so I'll need a consistent way of understanding and generating them correctly.

laurrentt commented 5 years ago

I was skeptical at first, mainly because I didn't get that the actual gathering of information would be left outside arnparse. But I like the idea and I think it's compatible with the goal of this library.