Skip to content

Commit 5c0080e

Browse files
[minor] Created sts module (#56)
* New sts module and doc updates * added missing branch declaration in update-readme.yml
1 parent 43f5896 commit 5c0080e

20 files changed

+588
-326
lines changed

.github/workflows/update-readme.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
- cron: "0 11 * * *" # 6 AM EST = 11 AM UTC
66
workflow_dispatch:
77
push:
8+
branches:
9+
- main
810
paths:
911
- .github/workflows/update-readme.yml
1012
- readme.py

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ repos:
2525
name: pytest
2626
alias: pytest
2727
types: [python]
28-
entry: python -m pytest -v tests/
28+
entry: python -m pytest -v tests/ -s
2929
language: system
3030
always_run: true
3131
pass_filenames: false

README.md

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,23 @@
5656
- Drop-in replacement for `boto3.session.Session`
5757
- Supports `assume_role` configuration, custom STS clients, and profile / region configuration, as well as all other parameters supported by `boto3.session.Session`
5858
- Tested, documented, and published to PyPI
59-
- Used in production at major tech companies
6059

61-
## Adoption and Recognition
60+
## Recognition, Adoption, and Testimonials
6261

63-
[Mentioned in TL;DR Sec](https://tldrsec.com/p/tldr-sec-282).
62+
[Featured in TL;DR Sec.](https://tldrsec.com/p/tldr-sec-282)
6463

65-
Received honorable mention during AWS Community Day Midwest on June 5th, 2025.
64+
Recognized during AWS Community Day Midwest on June 5th, 2025.
6665

67-
Used by multiple teams and large companies including FAANG.
66+
A testimonial from a Cyber Security Engineer at a FAANG company:
6867

69-
The following line plot illustrates the adoption of BRS from the last three months in terms of average daily downloads over a rolling seven day window.
68+
> _Most of my work is on tooling related to AWS security, so I'm pretty choosy about boto3 credentials-adjacent code. I often opt to just write this sort of thing myself so I at least know that I can reason about it. But I found boto3-refresh-session to be very clean and intuitive [...] We're using the RefreshableSession class as part of a client cache construct [...] We're using AWS Lambda to perform lots of operations across several regions in hundreds of accounts, over and over again, all day every day. And it turns out that there's a surprising amount of overhead to creating boto3 clients (mostly deserializing service definition json), so we can run MUCH more efficiently if we keep a cache of clients, all equipped with automatically refreshing sessions._
69+
70+
The following line plot illustrates the adoption of BRS over the last three months in terms of average daily downloads over a rolling seven day window.
7071

7172
<p align="center">
7273
<img src="https://raw.githubusercontent.com/michaelthomasletts/boto3-refresh-session/refs/heads/main/doc/downloads.png" />
7374
</p>
7475

75-
## Testimonials
76-
77-
From a Cyber Security Engineer at a FAANG company:
78-
79-
> _Most of my work is on tooling related to AWS security, so I'm pretty choosy about boto3 credentials-adjacent code. I often opt to just write this sort of thing myself so I at least know that I can reason about it. But I found boto3-refresh-session to be very clean and intuitive [...] We're using the RefreshableSession class as part of a client cache construct [...] We're using AWS Lambda to perform lots of operations across several regions in hundreds of accounts, over and over again, all day every day. And it turns out that there's a surprising amount of overhead to creating boto3 clients (mostly deserializing service definition json), so we can run MUCH more efficiently if we keep a cache of clients, all equipped with automatically refreshing sessions._
80-
8176
## Installation
8277

8378
```bash
@@ -125,27 +120,28 @@ buckets = s3.list_buckets()
125120

126121
## Raison d'être
127122

128-
It is common for data pipelines and workflows that interact with the AWS API via
129-
`boto3` to run for a long time and, accordingly, for temporary credentials to
130-
expire.
123+
Long-running data pipelines, security tooling, ETL jobs, and cloud automation scripts frequently interact with the AWS API using boto3 — and often run into the same problem:
124+
125+
**Temporary credentials expire.**
126+
127+
When that happens, engineers typically fall back on one of two strategies:
128+
129+
- Wrapping AWS calls in try/except blocks that catch ClientError exceptions
130+
- Writing ad hoc logic to refresh credentials using botocore credentials internals
131131

132-
Usually, engineers deal with that problem one of two ways:
132+
Both approaches are fragile, tedious to maintain, and error-prone at scale.
133133

134-
- `try except` blocks that catch `ClientError` exceptions
135-
- A similar approach as that used in this project -- that is, using methods available
136-
within `botocore` for refreshing temporary credentials automatically.
137-
138-
Speaking personally, variations of the code found herein exists in code bases at
139-
nearly every company where I have worked. Sometimes, I turned that code into a module;
140-
other times, I wrote it from scratch. Clearly, that is inefficient.
134+
Over the years, I noticed that every company I worked for — whether a scrappy startup or FAANG — ended up with some variation of the same pattern:
135+
a small in-house module to manage credential refresh, written in haste, duplicated across services, and riddled with edge cases. Things only
136+
got more strange and difficult when I needed to run things in parallel.
141137

142-
I decided to finally turn that code into a proper Python package with unit testing,
143-
automatic documentation, and quality checks; the idea being that, henceforth, depending
144-
on my employer's open source policy, I may simply import this package instead of
145-
reproducing the code herein for the Nth time.
138+
Eventually, I decided to build boto3-refresh-session as a proper open-source Python package:
146139

147-
If any of that sounds relatable, then `boto3-refresh-session` should help you.
140+
- Fully tested
141+
- Extensible
142+
- Integrated with boto3 idioms
143+
- Equipped with automatic documentation and CI tooling
148144

149-
---
145+
**The goal:** to solve a real, recurring problem once — cleanly, consistently, and for everyone -- with multiple refresh strategies.
150146

151-
📄 Licensed under the MIT License.
147+
If you've ever written the same AWS credential-refresh boilerplate more than once, this library is for you.

README.template.md

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,23 @@
5656
- Drop-in replacement for `boto3.session.Session`
5757
- Supports `assume_role` configuration, custom STS clients, and profile / region configuration, as well as all other parameters supported by `boto3.session.Session`
5858
- Tested, documented, and published to PyPI
59-
- Used in production at major tech companies
6059

61-
## Adoption and Recognition
60+
## Recognition, Adoption, and Testimonials
6261

63-
[Mentioned in TL;DR Sec](https://tldrsec.com/p/tldr-sec-282).
62+
[Featured in TL;DR Sec.](https://tldrsec.com/p/tldr-sec-282)
6463

65-
Received honorable mention during AWS Community Day Midwest on June 5th, 2025.
64+
Recognized during AWS Community Day Midwest on June 5th, 2025.
6665

67-
Used by multiple teams and large companies including FAANG.
66+
A testimonial from a Cyber Security Engineer at a FAANG company:
6867

69-
The following line plot illustrates the adoption of BRS from the last three months in terms of average daily downloads over a rolling seven day window.
68+
> _Most of my work is on tooling related to AWS security, so I'm pretty choosy about boto3 credentials-adjacent code. I often opt to just write this sort of thing myself so I at least know that I can reason about it. But I found boto3-refresh-session to be very clean and intuitive [...] We're using the RefreshableSession class as part of a client cache construct [...] We're using AWS Lambda to perform lots of operations across several regions in hundreds of accounts, over and over again, all day every day. And it turns out that there's a surprising amount of overhead to creating boto3 clients (mostly deserializing service definition json), so we can run MUCH more efficiently if we keep a cache of clients, all equipped with automatically refreshing sessions._
69+
70+
The following line plot illustrates the adoption of BRS over the last three months in terms of average daily downloads over a rolling seven day window.
7071

7172
<p align="center">
7273
<img src="https://raw.githubusercontent.com/michaelthomasletts/boto3-refresh-session/refs/heads/main/doc/downloads.png" />
7374
</p>
7475

75-
## Testimonials
76-
77-
From a Cyber Security Engineer at a FAANG company:
78-
79-
> _Most of my work is on tooling related to AWS security, so I'm pretty choosy about boto3 credentials-adjacent code. I often opt to just write this sort of thing myself so I at least know that I can reason about it. But I found boto3-refresh-session to be very clean and intuitive [...] We're using the RefreshableSession class as part of a client cache construct [...] We're using AWS Lambda to perform lots of operations across several regions in hundreds of accounts, over and over again, all day every day. And it turns out that there's a surprising amount of overhead to creating boto3 clients (mostly deserializing service definition json), so we can run MUCH more efficiently if we keep a cache of clients, all equipped with automatically refreshing sessions._
80-
8176
## Installation
8277

8378
```bash
@@ -125,27 +120,28 @@ buckets = s3.list_buckets()
125120

126121
## Raison d'être
127122

128-
It is common for data pipelines and workflows that interact with the AWS API via
129-
`boto3` to run for a long time and, accordingly, for temporary credentials to
130-
expire.
123+
Long-running data pipelines, security tooling, ETL jobs, and cloud automation scripts frequently interact with the AWS API using boto3 — and often run into the same problem:
124+
125+
**Temporary credentials expire.**
126+
127+
When that happens, engineers typically fall back on one of two strategies:
128+
129+
- Wrapping AWS calls in try/except blocks that catch ClientError exceptions
130+
- Writing ad hoc logic to refresh credentials using botocore credentials internals
131131

132-
Usually, engineers deal with that problem one of two ways:
132+
Both approaches are fragile, tedious to maintain, and error-prone at scale.
133133

134-
- `try except` blocks that catch `ClientError` exceptions
135-
- A similar approach as that used in this project -- that is, using methods available
136-
within `botocore` for refreshing temporary credentials automatically.
137-
138-
Speaking personally, variations of the code found herein exists in code bases at
139-
nearly every company where I have worked. Sometimes, I turned that code into a module;
140-
other times, I wrote it from scratch. Clearly, that is inefficient.
134+
Over the years, I noticed that every company I worked for — whether a scrappy startup or FAANG — ended up with some variation of the same pattern:
135+
a small in-house module to manage credential refresh, written in haste, duplicated across services, and riddled with edge cases. Things only
136+
got more strange and difficult when I needed to run things in parallel.
141137

142-
I decided to finally turn that code into a proper Python package with unit testing,
143-
automatic documentation, and quality checks; the idea being that, henceforth, depending
144-
on my employer's open source policy, I may simply import this package instead of
145-
reproducing the code herein for the Nth time.
138+
Eventually, I decided to build boto3-refresh-session as a proper open-source Python package:
146139

147-
If any of that sounds relatable, then `boto3-refresh-session` should help you.
140+
- Fully tested
141+
- Extensible
142+
- Integrated with boto3 idioms
143+
- Equipped with automatic documentation and CI tooling
148144

149-
---
145+
**The goal:** to solve a real, recurring problem once — cleanly, consistently, and for everyone -- with multiple refresh strategies.
150146

151-
📄 Licensed under the MIT License.
147+
If you've ever written the same AWS credential-refresh boilerplate more than once, this library is for you.

boto3_refresh_session/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
__all__ = []
2-
3-
from . import session
41
from .session import RefreshableSession
2+
from .sts import STSRefreshableSession
53

6-
__all__.extend(session.__all__)
4+
__all__ = ["RefreshableSession"]
75
__version__ = "1.0.41"
86
__author__ = "Mike Letts"

0 commit comments

Comments
 (0)