You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been doing a lot of cross-account work (using a variant of boto/botocore#761; still longing for that feature... please merge one of the PRs for it!!) so I rarely actually call the top-level boto3.resource, instead specifying the boto3 session I'd like to get the resource from.
A really nice thing about resources is that I can pass them to helper functions and they carry all the account knowledge in their own closures, so I can just deal with resources in many cases. Unfortunately the abstraction breaks when given one resource, I need to acquire more resources/clients from the same session.
Take this for example:
# I want this to be implementabledefsession(boto3_resource):
# return boto3_resource.meta.session # something like thispassdeffoo(bucketInAccountA, bucketInAccountB):
# I can do all sorts of fun things to the two buckets without# worrying about what account they're in.# Now my logic needs to get some security groups in the same# account as bucketInAccountAec2_A=session(bucketInAccountA).resource('ec2')
foo=ec2_A.security_groups.all()
doStuffWith(bucketInAccountA, foo)
Of course, I could always pass in the underlying session, but these things often nest and it feels silly to pass around redundant information when I know the session is trapped somewhere in the resource's closure. For all I know, it might already be accessible, but poking around in a REPL or in the source didn't help me much. I've seen that there's a myResource.meta.client that gives me a botocore client, but I'm not sure how to go from that back to a boto3 session.
Ultimately it seems like there could be a .meta.session attribute on all resources that would allow us to get back to the parent session.
The text was updated successfully, but these errors were encountered:
Marking as a tentative feature request. I think this might need a few design iterations and discussion. While the simplest solution would be to add a .meta.session, I do remember we tried to minimize the number of objects that know about the session to simplify code.
I would also be interested in alternative ways to accomplish what you're ultimately after, being able to retrieve create resources using the same session from a given resource.
Greetings! It looks like this issue hasn’t been active in longer than one year. We encourage you to check if this is still an issue in the latest release. In the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or upvote with a reaction on the initial post to prevent automatic closure. If the issue is already closed, please feel free to open a new one.
This is still an issue, and makes using the resource API difficult in larger applications, especially if one is working with multiple AWS accounts or credentials.
I've been doing a lot of cross-account work (using a variant of boto/botocore#761; still longing for that feature... please merge one of the PRs for it!!) so I rarely actually call the top-level
boto3.resource
, instead specifying the boto3 session I'd like to get the resource from.A really nice thing about resources is that I can pass them to helper functions and they carry all the account knowledge in their own closures, so I can just deal with resources in many cases. Unfortunately the abstraction breaks when given one resource, I need to acquire more resources/clients from the same session.
Take this for example:
Of course, I could always pass in the underlying session, but these things often nest and it feels silly to pass around redundant information when I know the session is trapped somewhere in the resource's closure. For all I know, it might already be accessible, but poking around in a REPL or in the source didn't help me much. I've seen that there's a
myResource.meta.client
that gives me a botocore client, but I'm not sure how to go from that back to a boto3 session.Ultimately it seems like there could be a
.meta.session
attribute on all resources that would allow us to get back to the parent session.The text was updated successfully, but these errors were encountered: