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

Add utility for handling temporary boto sessions #1174

Closed
thomasklinger1234 opened this issue Jun 11, 2021 · 12 comments
Closed

Add utility for handling temporary boto sessions #1174

thomasklinger1234 opened this issue Jun 11, 2021 · 12 comments
Labels

Comments

@thomasklinger1234
Copy link

Is your feature request related to a problem? Please describe.

When using the STS AssumeRole API to perform tasks in the context of another IAM role, there is usually a lot of boilerplate code to write:

credentials = sts.assume_role(RoleArn="...", "RoleSessionName="...")["Credentials"]
ec2 = boto3.Session(aws_session_token=credentials["SessionToken"], ...).client("ec2")

This feature request is about adding a new small helper utility for switching roles during Lambda invocations easier.

Describe the solution you'd like
A contextmanager for assuming a session for given context, something like

from aws_lambda_powertools.utilities import scoped_session

with scoped_session("ec2", role_arn="<role-arn>") as ec2:
  ec2.describe_regions()

Describe alternatives you've considered

Maybe there is also the possibility to do this using a decorator but I have no good API design for that.

@heitorlessa
Copy link
Contributor

hey @thomasklinger1234 thanks for raising this - I believe this solidifies the idea of having a SDK Helper utility with these and other functions.

What do you think @jplock?

Example: #1187

@lorengordon
Copy link

lorengordon commented Jul 1, 2021

Fwiw, I've been using and love @benkehoe's utility https://github.com/benkehoe/aws-assume-role-lib for this kind of assume-role functionality in lambda funtions. Lot of good lessons there.

@benkehoe
Copy link

benkehoe commented Jul 1, 2021

Huh, I have never though about a context manager for role assumption, though I don't see much value as there's nothing for it to do for cleanup or exception handling. The other thing that you want to avoid is doing it on a per-client (e.g., EC2) basis, this is what boto3 sessions are for (and I would suggest guiding people towards sessions rather than hiding them).
You could just import aws_assume_role_lib.assume_role() into utilities so users don't need to discover and import it separately?

@heitorlessa
Copy link
Contributor

heitorlessa commented Jul 1, 2021 via email

@ran-isenberg
Copy link
Contributor

@heitorlessa When we package our lambdas, we explicitly remove boto from the zip file as it's already present in the container image of Lambda. It reduced our zipped by a lot.

@lorengordon
Copy link

I wish the lambda runtimes would update their boto3/botocore libraries more often, and make it less necessary to include these in the package. Unfortunately, the versions are often quite out-of-date.

@lorengordon
Copy link

But another good reason to package them anyway is to ensure we are using the same versions we test against...

@ran-isenberg
Copy link
Contributor

ran-isenberg commented Jul 18, 2021

how do you know what version is merged and actually working? there's also the "older" boto there.

@lorengordon
Copy link

lorengordon commented Jul 18, 2021

We don't use the original boto v1. The boto3 and botocore versions we use are a requirement of our lambda code, not this library. The packaging logic for the lambda function just needs to support some mechanism of specifying exact versions. We use a requirements.txt file, with Dependabot incrementing the version periodically, and CI/CD exercising the change in our test suite. Pretty straightforward.

@heitorlessa
Copy link
Contributor

Thanks a lot everyone - I'm moving this to the official Roadmap to give other customers visibility, as Typescript and C# Powertools are also ramping up quickly to public beta.

Short-term plan is to create a RFC to support SDK high level utilities and gather ideas on what to include. Mid-term, we're working to document the new dynamic feature toggles utility, integrate API reference into the docs, and rewrite the docs for Data Classes and Parser to make it friendlier.

Once these are complete, or if I could get help in parallel, I'd love to have these and other high level utilities for SDK.

@heitorlessa heitorlessa transferred this issue from aws-powertools/powertools-lambda-python Jul 26, 2021
@heitorlessa heitorlessa transferred this issue from aws-powertools/powertools-lambda Apr 28, 2022
@heitorlessa heitorlessa added need-customer-feedback Requires more customers feedback before making or revisiting a decision and removed Proposed labels May 20, 2022
@heitorlessa heitorlessa added the feature-request feature request label Jun 13, 2022
@sthulb sthulb moved this from Triage to Ideas in Powertools for AWS Lambda (Python) Jun 19, 2023
@anafalcao
Copy link
Collaborator

Hey everyone!
Closing this issue as it's been open for a while now, and we didn't have much customer feedback.
Please open a new one if it's still an issue.

@anafalcao anafalcao closed this as not planned Won't fix, can't repro, duplicate, stale Jan 22, 2025
@github-project-automation github-project-automation bot moved this from Ideas to Coming soon in Powertools for AWS Lambda (Python) Jan 22, 2025
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@dreamorosi dreamorosi moved this from Coming soon to Closed in Powertools for AWS Lambda (Python) Jan 22, 2025
@dreamorosi dreamorosi added rejected and removed need-customer-feedback Requires more customers feedback before making or revisiting a decision labels Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

7 participants