arn
arn copied to clipboard
Allow ARNs to retrieve region and account from Boto3 session
A boto3 Session object has the Session.region_name field, and can call Session.client('sts').get_caller_identity() to discover the account in which it is operating (this call has no authorization check, so it is always allowed). When creating an ARN class, I should be able to tell it to use either the default session, or a session I provide, to discover these values (subject to whether the ARN needs those values, as covered in #7).
Are you imagining it would behave like manually overriding those fields?
So:
SomeArn(
"arn:aws:...",
session=some_boto_session,
)
would be a shortcut for
SomeArn(
"arn:aws:...",
region=session.region_name,
account=session.client("sts").get_caller_identity()["Account"]
)
?
Or did you have something else in mind?
Yes, exactly that, though with two clarifications:
- I think you should be able to do
SomeArn("...", session='default')or=Trueor whatever and have it useboto3._get_default_session() - With #7 it should only extract those values if the ARN needs the region and/or account (so it's not precisely the shortcut you indicate)