Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A mechanism to get a session back from a resource #747

Closed
copumpkin opened this issue Aug 2, 2016 · 4 comments
Closed

A mechanism to get a session back from a resource #747

copumpkin opened this issue Aug 2, 2016 · 4 comments

Comments

@copumpkin
Copy link

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 implementable
def session(boto3_resource):
    # return boto3_resource.meta.session # something like this
    pass

def foo(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 bucketInAccountA
    ec2_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.

@jamesls
Copy link
Member

jamesls commented Aug 3, 2016

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.

@jamesls jamesls added feature-request This issue requests a feature. needs-discussion labels Aug 3, 2016
@Varriount
Copy link

Would there be a way to do this via the events API?

@github-actions
Copy link

github-actions bot commented Oct 6, 2021

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.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Oct 6, 2021
@github-actions github-actions bot closed this as completed Oct 9, 2021
@Varriount
Copy link

Varriount commented Dec 13, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants