boto3-refresh-session 1.0.36__py3-none-any.whl → 6.2.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,569 @@
1
+ Metadata-Version: 2.4
2
+ Name: boto3-refresh-session
3
+ Version: 6.2.7
4
+ Summary: A simple Python package for refreshing the temporary security credentials in a boto3.session.Session object automatically.
5
+ License: MIT
6
+ License-File: LICENSE
7
+ License-File: NOTICE
8
+ Keywords: boto3,botocore,aws,sts,credentials,token,refresh,iot,x509,mqtt
9
+ Author: Mike Letts
10
+ Author-email: lettsmt@gmail.com
11
+ Maintainer: Michael Letts
12
+ Maintainer-email: lettsmt@gmail.com
13
+ Requires-Python: >=3.10
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Requires-Dist: awscrt
22
+ Requires-Dist: awsiotsdk
23
+ Requires-Dist: boto3
24
+ Requires-Dist: botocore
25
+ Requires-Dist: requests
26
+ Requires-Dist: typing-extensions
27
+ Project-URL: Documentation, https://michaelthomasletts.github.io/boto3-refresh-session/index.html
28
+ Project-URL: Repository, https://github.com/michaelthomasletts/boto3-refresh-session
29
+ Description-Content-Type: text/markdown
30
+
31
+ <div align="center">
32
+ <img src="https://raw.githubusercontent.com/michaelthomasletts/boto3-refresh-session/refs/heads/main/doc/brs.png" />
33
+ </div>
34
+
35
+ </br>
36
+
37
+ <div align="center"><em>
38
+ A simple Python package for refreshing the temporary security credentials in a <code>boto3.session.Session</code> object automatically.
39
+ </em></div>
40
+
41
+ </br>
42
+
43
+ <div align="center">
44
+
45
+ <a href="https://pypi.org/project/boto3-refresh-session/">
46
+ <img
47
+ src="https://img.shields.io/pypi/v/boto3-refresh-session?color=%23FF0000FF&logo=python&label=Latest%20Version"
48
+ alt="pypi_version"
49
+ />
50
+ </a>
51
+
52
+ <a href="https://pypi.org/project/boto3-refresh-session/">
53
+ <img
54
+ src="https://img.shields.io/pypi/pyversions/boto3-refresh-session?style=pypi&color=%23FF0000FF&logo=python&label=Compatible%20Python%20Versions"
55
+ alt="py_version"
56
+ />
57
+ </a>
58
+
59
+ <a href="https://github.com/michaelthomasletts/boto3-refresh-session/actions/workflows/push.yml">
60
+ <img
61
+ src="https://img.shields.io/github/actions/workflow/status/michaelthomasletts/boto3-refresh-session/push.yml?logo=github&color=%23FF0000FF&label=Build"
62
+ alt="workflow"
63
+ />
64
+ </a>
65
+
66
+ <a href="https://github.com/michaelthomasletts/boto3-refresh-session/commits/main">
67
+ <img
68
+ src="https://img.shields.io/github/last-commit/michaelthomasletts/boto3-refresh-session?logo=github&color=%23FF0000FF&label=Last%20Commit"
69
+ alt="last_commit"
70
+ />
71
+ </a>
72
+
73
+ <a href="https://github.com/michaelthomasletts/boto3-refresh-session/stargazers">
74
+ <img
75
+ src="https://img.shields.io/github/stars/michaelthomasletts/boto3-refresh-session?style=flat&logo=github&labelColor=555&color=FF0000&label=Stars"
76
+ alt="stars"
77
+ />
78
+ </a>
79
+
80
+ <a href="https://pepy.tech/projects/boto3-refresh-session">
81
+ <img
82
+ src="https://img.shields.io/endpoint?url=https%3A%2F%2Fmichaelthomasletts.github.io%2Fpepy-stats%2Fboto3-refresh-session.json&style=flat&logo=python&labelColor=555&color=FF0000"
83
+ alt="downloads"
84
+ />
85
+ </a>
86
+
87
+
88
+ <a href="https://michaelthomasletts.github.io/boto3-refresh-session/index.html">
89
+ <img
90
+ src="https://img.shields.io/badge/Official%20Documentation-📘-FF0000?style=flat&labelColor=555&logo=readthedocs"
91
+ alt="documentation"
92
+ />
93
+ </a>
94
+
95
+ <a href="https://github.com/michaelthomasletts/boto3-refresh-session">
96
+ <img
97
+ src="https://img.shields.io/badge/Source%20Code-💻-FF0000?style=flat&labelColor=555&logo=github"
98
+ alt="github"
99
+ />
100
+ </a>
101
+
102
+ <a href="https://michaelthomasletts.github.io/boto3-refresh-session/qanda.html">
103
+ <img
104
+ src="https://img.shields.io/badge/Q%26A-❔-FF0000?style=flat&labelColor=555&logo=vercel&label=Q%26A"
105
+ alt="qanda"
106
+ />
107
+ </a>
108
+
109
+ <a href="https://michaelthomasletts.github.io/blog/brs-rationale/">
110
+ <img
111
+ src="https://img.shields.io/badge/Blog%20Post-📘-FF0000?style=flat&labelColor=555&logo=readthedocs"
112
+ alt="blog"
113
+ />
114
+ </a>
115
+
116
+ <a href="https://github.com/sponsors/michaelthomasletts">
117
+ <img
118
+ src="https://img.shields.io/badge/Sponsor%20this%20Project-💙-FF0000?style=flat&labelColor=555&logo=githubsponsors"
119
+ alt="sponsorship"
120
+ />
121
+ </a>
122
+
123
+ </div>
124
+
125
+ ## 😛 Features
126
+
127
+ - Drop-in replacement for `boto3.session.Session`
128
+ - MFA support included for STS
129
+ - SSO support via AWS profiles
130
+ - Optionally caches boto3 clients
131
+ - Supports automatic temporary credential refresh for:
132
+ - **STS**
133
+ - **IoT Core**
134
+ - X.509 certificates w/ role aliases over mTLS (PEM files and PKCS#11)
135
+ - MQTT actions are available!
136
+ - [Tested](https://github.com/michaelthomasletts/boto3-refresh-session/tree/main/tests), [documented](https://michaelthomasletts.github.io/boto3-refresh-session/index.html), and [published to PyPI](https://pypi.org/project/boto3-refresh-session/)
137
+
138
+ ## 😌 Recognition and Testimonials
139
+
140
+ [Featured in TL;DR Sec.](https://tldrsec.com/p/tldr-sec-282)
141
+
142
+ [Featured in CloudSecList.](https://cloudseclist.com/issues/issue-290)
143
+
144
+ Recognized during AWS Community Day Midwest on June 5th, 2025 (the founder's birthday!).
145
+
146
+ A testimonial from a Cyber Security Engineer at a FAANG company:
147
+
148
+ > _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._
149
+
150
+ ## 💻 Installation
151
+
152
+ ```bash
153
+ pip install boto3-refresh-session
154
+ ```
155
+
156
+ ## 🏃 Quick Start Guide
157
+
158
+ The following example shows how to:
159
+
160
+ - Initialize `RefreshableSession` _using an AWS profile_
161
+ - Enable MFA support
162
+ - Initialize an S3 client with some configurations
163
+
164
+ ```python
165
+ from boto3_refresh_session import RefreshableSession
166
+ from botocore.config import Config
167
+ import subprocess
168
+
169
+
170
+ def mfa_token_provider(cmd: list[str], timeout: float = 10.0):
171
+ """Returns an MFA code. Accepts commands which emit tokens."""
172
+
173
+ p = subprocess.run(
174
+ cmd,
175
+ check=False,
176
+ capture_output=True,
177
+ text=True,
178
+ timeout=timeout,
179
+ )
180
+ return (p.stdout or "").strip()
181
+
182
+
183
+ session = RefreshableSession(
184
+ assume_role_kwargs={
185
+ "RoleArn": "arn:aws:iam::123456789012:role/CoolGuy", # required
186
+ "RoleSessionName": "just-goofin-around", # defaults to 'boto3-refresh-session'
187
+ "SerialNumber": "arn:aws:iam::123456789012:mfa/test-user", # required if using MFA
188
+ },
189
+ mfa_token_provider=mfa_token_provider, # required if using MFA
190
+ mfa_token_provider_kwargs={ # depends on if mfa_token_provider needs args
191
+ "cmd": ["ykman", "oath", "code", "--single", "AWS-prod"],
192
+ "timeout": 3.0
193
+ },
194
+ profile_name="test-aws-profile",
195
+ region_name="us-east-1",
196
+ )
197
+ s3 = session.client("s3", config=Config(retries={"max_attempts": 2}))
198
+ s3.list_buckets()
199
+ ```
200
+
201
+ ## 📝 Usage
202
+
203
+ <details>
204
+ <summary><strong>Core Concepts (click to expand)</strong></summary>
205
+
206
+ ### Core Concepts
207
+
208
+ 1. `RefreshableSession` is the intended interface for using `boto3-refresh-session`. Whether you're using this package to refresh temporary credentials returned by STS, the IoT credential provider (which is really just STS, but I digress), or some custom authentication or credential provider, `RefreshableSession` is where you *ought to* be working when using `boto3-refresh-session`.
209
+
210
+ 2. *You can use all of the same keyword parameters normally associated with `boto3.session.Session`!* For instance, suppose you want to pass `region_name` to `RefreshableSession` as a parameter, whereby it's passed to `boto3.session.Session`. That's perfectly fine! Just pass it like you normally would when initializing `boto3.session.Session`. These keyword parameters are *completely optional*, though. If you're confused, the main idea to remember is this: if initializing `boto3.session.Session` *requires* a particular keyword parameter then pass it to `RefreshableSession`; if not, don't worry about it.
211
+
212
+ 3. To tell `RefreshableSession` which AWS service you're working with for authentication and credential retrieval purposes (STS vs. IoT vs. some custom credential provider), you'll need to pass a `method` parameter to `RefreshableSession`. Since the `service_name` namespace is already occupied by `boto3.sesssion.Session`, [`boto3-refresh-session` uses `method` instead of "service" so as to avoid confusion](https://github.com/michaelthomasletts/boto3-refresh-session/blob/04acb2adb34e505c4dc95711f6b2f97748a2a489/boto3_refresh_session/utils/typing.py#L40). If you're using `RefreshableSession` for STS, however, then `method` is set to `"sts"` by default. You don't need to pass the `method` keyword argument in that case.
213
+
214
+ 4. Using `RefreshableSession` for STS, IoT, or custom flows requires different keyword parameters that are unique to those particular methods. For instance, `STSRefreshableSession`, which is the engine for STS in `boto3-refresh-session`, requires `assume_role_kwargs` and optionally allows `sts_client_kwargs` whereas `CustomRefreshableSession` and `IoTX509RefreshableSession` do not. To familiarize yourself with the keyword parameters for each method, check the documentation for each of those engines [in the Refresh Strategies section here](https://michaelthomasletts.com/boto3-refresh-session/modules/index.html).
215
+
216
+ 5. Irrespective of whatever `method` you pass as a keyword parameter, `RefreshableSession` accepts a keyword parameter named `defer_refresh`. Basically, this boolean tells `boto3-refresh-session` either to refresh credentials *the moment they expire* or to *wait until credentials are explicitly needed*. If you are working in a low-latency environment then `defer_refresh = False` might be helpful. For most users, however, `defer_refresh = True` is most desirable. For that reason, `defer_refresh = True` is the default value. Most users, therefore, should not concern themselves too much with this feature.
217
+
218
+ 6. Some developers struggle to imagine where `boto3-refresh-session` might be helpful. To figure out if `boto3-refresh-session` is for your use case, or whether `credential_process` satisfies your needs, check out [this blog post](https://michaelthomasletts.com/blog/brs-rationale/). `boto3-refresh-session` is not for every developer or use-case; it is a niche tool.
219
+
220
+ 7. `boto3-refresh-session` supports client caching in order to minimize the massive memory footprint associated with duplicative clients. By default, `RefreshableSession` caches clients. To deactivate this feature, set `cache_clients=False`.
221
+
222
+ 8. `boto3-refresh-session` supports MFA. Refer to the MFA section further below for more details.
223
+
224
+ 9. `boto3-refresh-session` supports SSO; however, it _does not_ and _will never_ automatically handle `sso login` for you -- that is, not unless you write your own hacky custom credential getter and pass that to `RefreshableSession(method="custom", ...)`, which I do not recommend (but cannot prevent you from doing).
225
+
226
+ </details>
227
+
228
+ <details>
229
+ <summary><strong>Clients (click to expand)</strong></summary>
230
+
231
+ ### Clients
232
+
233
+ Most developers who use `boto3` interact primarily with `boto3.client` instead of `boto3.session.Session`. But many developers may not realize that `boto3.session.Session` belies `boto3.client`! In fact, that's precisely what makes `boto3-refresh-session` possible!
234
+
235
+ Before we get to initializing clients via `RefreshableSession`, however, let's briefly talk about `boto3` clients and memory . . .
236
+
237
+ Clients consume a shocking amount of memory. So much so that many developers create their own bespoke client cache. To minimize the memory footprint associated with duplicative clients, as well as make the lives of developers a little easier, `boto3-refresh-session` includes a `cache_clients` parameter which, by default, caches clients according to the parameters passed to the `client` method!
238
+
239
+ With client caching out of the way, in order to use the `boto3.client` interface, but with the benefits of `boto3-refresh-session`, you have a few options! In the following examples, let's assume you want to use STS for retrieving temporary credentials for the sake of simplicity. Let's also focus specifically on `client`. Switching to `resource` follows the same exact idioms as below, except that `client` must be switched to `resource` in the pseudo-code, obviously. If you are not sure how to use `RefreshableSession` for STS (or custom auth flows) then check the usage instructions in the following sections!
240
+
241
+ ##### `RefreshableSession.client` (Recommended)
242
+
243
+ So long as you reuse the same `session` object when creating `client` objects, this approach can be used everywhere in your code.
244
+
245
+ ```python
246
+ from boto3_refresh_session import RefreshableSession
247
+
248
+ assume_role_kwargs = {
249
+ "RoleArn": "<your-role-arn>",
250
+ "RoleSessionName": "<your-role-session-name>",
251
+ "DurationSeconds": "<your-selection>",
252
+ ...
253
+ }
254
+ session = RefreshableSession(assume_role_kwargs=assume_role_kwargs)
255
+ s3 = session.client("s3")
256
+ ```
257
+
258
+ ##### `DEFAULT_SESSION`
259
+
260
+ This technique can be helpful if you want to use the same instance of `RefreshableSession` everywhere in your code without reference to `boto3_refresh_session`!
261
+
262
+ ```python
263
+ from boto3 import DEFAULT_SESSION, client
264
+ from boto3_refresh_session import RefreshableSession
265
+
266
+ assume_role_kwargs = {
267
+ "RoleArn": "<your-role-arn>",
268
+ "RoleSessionName": "<your-role-session-name>",
269
+ "DurationSeconds": "<your-selection>",
270
+ ...
271
+ }
272
+ DEFAULT_SESSION = RefreshableSession(assume_role_kwargs=assume_role_kwargs)
273
+ s3 = client("s3")
274
+ ```
275
+
276
+ ##### `botocore_session`
277
+
278
+ ```python
279
+ from boto3 import client
280
+ from boto3_refresh_session import RefreshableSession
281
+
282
+ assume_role_kwargs = {
283
+ "RoleArn": "<your-role-arn>",
284
+ "RoleSessionName": "<your-role-session-name>",
285
+ "DurationSeconds": "<your-selection>",
286
+ ...
287
+ }
288
+ s3 = client(
289
+ service_name="s3",
290
+ botocore_session=RefreshableSession(assume_role_kwargs=assume_role_kwargs)
291
+ )
292
+ ```
293
+
294
+ </details>
295
+
296
+ <details>
297
+ <summary><strong>STS (click to expand)</strong></summary>
298
+
299
+ ### STS
300
+
301
+ Most developers use AWS STS to assume an IAM role and return a set of temporary security credentials. boto3-refresh-session can be used to ensure those temporary credentials refresh automatically. For additional information on the exact parameters that `RefreshableSession` takes for STS, [check this documentation](https://michaelthomasletts.com/boto3-refresh-session/modules/generated/boto3_refresh_session.methods.sts.STSRefreshableSession.html).
302
+
303
+ ```python
304
+ import boto3_refresh_session as brs
305
+
306
+
307
+ assume_role_kwargs = {
308
+ "RoleArn": "<your IAM role arn>", # required
309
+ "RoleSessionName": "<your role session name>", # required
310
+ ...
311
+ }
312
+
313
+ session = brs.RefreshableSession(
314
+ assume_role_kwargs=assume_role_kwargs, # required
315
+ sts_client_kwargs={...}, # optional
316
+ ... # misc. params for boto3.session.Session
317
+ )
318
+ ```
319
+
320
+ </details>
321
+
322
+ <details>
323
+ <summary><strong>MFA (click to expand)</strong></summary>
324
+
325
+ ### MFA Support
326
+
327
+ When assuming a role that requires MFA, `boto3-refresh-session` supports automatic token provisioning through the `mfa_token_provider` parameter. This parameter accepts a callable that returns a fresh MFA token code (string) whenever credentials need to be refreshed.
328
+
329
+ The `mfa_token_provider` approach is **strongly recommended** over manually providing `TokenCode` in `assume_role_kwargs`, as MFA tokens expire after 30 seconds while AWS temporary credentials can last for hours. By using a callable, your application can automatically fetch fresh tokens on each refresh without manual intervention. There is nothing preventing you from manually providing `TokenCode` *without* `mfa_token_provider`; however, *you* will be responsible for updating `TokenCode` *before* automatic temporary credential refresh occurs, which is likely to be a fragile and complicated approach.
330
+
331
+ When using `mfa_token_provider`, you must also provide `SerialNumber` (your MFA device ARN) in `assume_role_kwargs`. For additional information on the exact parameters that `RefreshableSession` takes for MFA, [check this documentation](https://michaelthomasletts.com/boto3-refresh-session/modules/generated/boto3_refresh_session.methods.sts.STSRefreshableSession.html).
332
+
333
+ ⚠️ Most developers will probably find example number four most helpful.
334
+
335
+ #### Examples
336
+
337
+ ```python
338
+ import boto3_refresh_session as brs
339
+
340
+ # Example 1: Interactive prompt for MFA token
341
+ def get_mfa_token():
342
+ return input("Enter MFA token: ")
343
+
344
+ # we'll reuse this object in each example for simplicity :)
345
+ assume_role_kwargs = {
346
+ "RoleArn": "<your-role-arn>",
347
+ "RoleSessionName": "<your-role-session-name>",
348
+ "SerialNumber": "arn:aws:iam::123456789012:mfa/your-user", # required with mfa_token_provider
349
+ }
350
+
351
+ session = brs.RefreshableSession(
352
+ assume_role_kwargs=assume_role_kwargs,
353
+ mfa_token_provider=get_mfa_token, # callable that returns MFA token
354
+ )
355
+
356
+ # Example 2: Using pyotp for TOTP-based MFA
357
+ import pyotp
358
+
359
+ def get_totp_token():
360
+ totp = pyotp.TOTP("<your-secret-key>")
361
+ return totp.now()
362
+
363
+ session = brs.RefreshableSession(
364
+ assume_role_kwargs=assume_role_kwargs,
365
+ mfa_token_provider=get_totp_token,
366
+ )
367
+
368
+ # Example 3: Retrieving token from environment variable or external service
369
+ import os
370
+
371
+ def get_env_token():
372
+ return os.environ.get("AWS_MFA_TOKEN", "")
373
+
374
+ session = brs.RefreshableSession(
375
+ assume_role_kwargs=assume_role_kwargs,
376
+ mfa_token_provider=get_env_token,
377
+ )
378
+
379
+ # Example 4: Using Yubikey (or any token provider CLI)
380
+ from typing import Sequence
381
+ import subprocess
382
+
383
+ def mfa_token_provider(cmd: Sequence[str], timeout: float):
384
+ p = subprocess.run(
385
+ list(cmd),
386
+ check=False,
387
+ capture_output=True,
388
+ text=True,
389
+ timeout=timeout,
390
+ )
391
+ return (p.stdout or "").strip()
392
+
393
+ mfa_token_provider_args = {
394
+ "cmd": ["ykman", "oath", "code", "--single", "AWS-prod"], # example token source
395
+ "timeout": 3.0,
396
+ }
397
+
398
+ session = RefreshableSession(
399
+ assume_role_kwargs=assume_role_kwargs,
400
+ mfa_token_provider=mfa_token_provider,
401
+ mfa_token_provider_args=mfa_token_provider_args,
402
+ )
403
+ ```
404
+ </details>
405
+
406
+ <details>
407
+ <summary><strong>SSO (click to expand)</strong></summary>
408
+
409
+ ### SSO
410
+
411
+ `boto3-refresh-session` supports SSO by virtue of AWS profiles.
412
+
413
+ The below pseudo-code illustrates how to assume an IAM role using an AWS profile with SSO. Not shown, however, is running `sso login` manually, which `boto3-refresh-session` does not perform automatically for you. Therefore, you must manually run `sso login` as necessary.
414
+
415
+ If you wish to automate `sso login` (not recommended) then you will need to write your own custom callable function and pass it to `RefreshableSession(method="custom", ...)`. In that event, please refer to the `Custom` documentation found in a separate section below.
416
+
417
+ ```python
418
+ from boto3_refresh_session import RefreshableSession
419
+
420
+ session = RefreshableSession(
421
+ assume_role_kwargs={
422
+ "RoleArn": "<your IAM role arn>",
423
+ "RoleSessionName": "<your role session name>",
424
+ },
425
+ profile_name="<your AWS profile name>",
426
+ ...
427
+ )
428
+ s3 = session.client("s3")
429
+ ```
430
+ </details>
431
+
432
+ <details>
433
+ <summary><strong>Custom (click to expand)</strong></summary>
434
+
435
+ ### Custom
436
+
437
+ If you have a highly sophisticated, novel, or idiosyncratic authentication flow not included in boto3-refresh-session then you will need to provide your own custom temporary credentials callable object. `RefreshableSession` accepts custom credentials callable objects, as shown below. For additional information on the exact parameters that `RefreshableSession` takes for custom authentication flows, [check this documentation](https://michaelthomasletts.com/boto3-refresh-session/modules/generated/boto3_refresh_session.methods.custom.CustomRefreshableSession.html#boto3_refresh_session.methods.custom.CustomRefreshableSession).
438
+
439
+ ```python
440
+ # create (or import) your custom credential method
441
+ def your_custom_credential_getter(...):
442
+ ...
443
+ return {
444
+ "access_key": ...,
445
+ "secret_key": ...,
446
+ "token": ...,
447
+ "expiry_time": ...,
448
+ }
449
+
450
+ # and pass it to RefreshableSession
451
+ session = RefreshableSession(
452
+ method="custom", # required
453
+ custom_credentials_method=your_custom_credential_getter, # required
454
+ custom_credentials_method_args=..., # optional
455
+ region_name=region_name, # optional
456
+ profile_name=profile_name, # optional
457
+ ... # misc. boto3.session.Session params
458
+ )
459
+ ```
460
+
461
+ </details>
462
+
463
+ <details>
464
+ <summary><strong>IoT Core X.509 (click to expand)</strong></summary>
465
+
466
+ ### IoT Core X.509
467
+
468
+ AWS IoT Core can vend temporary AWS credentials through the **credentials provider** when you connect with an X.509 certificate and a **role alias**. `boto3-refresh-session` makes this flow seamless by automatically refreshing credentials over **mTLS**.
469
+
470
+ For additional information on the exact parameters that `IOTX509RefreshableSession` takes, [check this documentation](https://michaelthomasletts.com/boto3-refresh-session/modules/generated/boto3_refresh_session.methods.iot.x509.IOTX509RefreshableSession.html).
471
+
472
+ ### PEM file
473
+
474
+ ```python
475
+ import boto3_refresh_session as brs
476
+
477
+ # PEM certificate + private key example
478
+ session = brs.RefreshableSession(
479
+ method="iot",
480
+ endpoint="<your-credentials-endpoint>.credentials.iot.<region>.amazonaws.com",
481
+ role_alias="<your-role-alias>",
482
+ certificate="/path/to/certificate.pem",
483
+ private_key="/path/to/private-key.pem",
484
+ thing_name="<your-thing-name>", # optional, if used in policies
485
+ duration_seconds=3600, # optional, capped by role alias
486
+ region_name="us-east-1",
487
+ )
488
+
489
+ # Now you can use the session like any boto3 session
490
+ s3 = session.client("s3")
491
+ print(s3.list_buckets())
492
+ ```
493
+
494
+ ### PKCS#11
495
+
496
+ ```python
497
+ session = brs.RefreshableSession(
498
+ method="iot",
499
+ endpoint="<your-credentials-endpoint>.credentials.iot.<region>.amazonaws.com",
500
+ role_alias="<your-role-alias>",
501
+ certificate="/path/to/certificate.pem",
502
+ pkcs11={
503
+ "pkcs11_lib": "/usr/local/lib/softhsm/libsofthsm2.so",
504
+ "user_pin": "1234",
505
+ "slot_id": 0,
506
+ "token_label": "MyToken",
507
+ "private_key_label": "MyKey",
508
+ },
509
+ thing_name="<your-thing-name>",
510
+ region_name="us-east-1",
511
+ )
512
+ ```
513
+
514
+ ### MQTT
515
+
516
+ After initializing a session object, you can can begin making actions with MQTT using the [mqtt method](https://github.com/michaelthomasletts/boto3-refresh-session/blob/deb68222925bf648f26e878ed4bc24b45317c7db/boto3_refresh_session/methods/iot/x509.py#L367)! You can reuse the same certificate, private key, et al as that used to initialize `RefreshableSession`. Or, alternatively, you can provide separate PKCS#11 or certificate information, whether those be file paths or bytes values. Either way, at a minimum, you will need to provide the endpoint and client identifier (i.e. thing name).
517
+
518
+ ```python
519
+ from awscrt.mqtt.QoS import AT_LEAST_ONCE
520
+ conn = session.mqtt(
521
+ endpoint="<your endpoint>-ats.iot.<region>.amazonaws.com",
522
+ client_id="<your thing name or client ID>",
523
+ )
524
+ conn.connect()
525
+ conn.connect().result()
526
+ conn.publish(topic="foo/bar", payload=b"hi", qos=AT_LEAST_ONCE)
527
+ conn.disconnect().result()
528
+ ```
529
+
530
+ </details>
531
+
532
+ ## ⚠️ Changes
533
+
534
+ Browse through the various changes to `boto3-refresh-session` over time.
535
+
536
+ #### 😥 v3.0.0
537
+
538
+ **The changes introduced by v3.0.0 will not impact ~99% of users** who generally interact with `boto3-refresh-session` by only `RefreshableSession`, *which is the intended usage for this package after all.*
539
+
540
+ Advanced users, however, particularly those using low-level objects such as `BaseRefreshableSession | refreshable_session | BRSSession | utils.py`, may experience breaking changes.
541
+
542
+ Please review [this PR](https://github.com/michaelthomasletts/boto3-refresh-session/pull/75) for additional details.
543
+
544
+ #### ✂️ v4.0.0
545
+
546
+ The `ecs` module has been dropped. For additional details and rationale, please review [this PR](https://github.com/michaelthomasletts/boto3-refresh-session/pull/78).
547
+
548
+ #### 😛 v5.0.0
549
+
550
+ Support for IoT Core via X.509 certificate-based authentication (over HTTPS) is now available!
551
+
552
+ #### ➕ v5.1.0
553
+
554
+ MQTT support added for IoT Core via X.509 certificate-based authentication.
555
+
556
+ #### ➕ v6.0.0
557
+
558
+ MFA support for STS added!
559
+
560
+ #### 🔒😥 v6.2.0
561
+
562
+ - Client caching introduced to `RefreshableSession` in order to minimize memory footprint! Available via `cache_clients` parameter.
563
+ - Testing suite expanded to include IOT, MFA, caching, and much more!
564
+ - A subtle bug was uncovered where `RefreshableSession` created refreshable credentials but boto3's underlying session continued to resolve credentials via the default provider chain (i.e. env vars, shared config, etc) unless explicitly wired. `get_credentials()` and clients could, in certain setups, use base session credentials instead of the refreshable STS/IoT/custom credentials via assumed role. To fix this, I updated the implementation in `BRSSession.__post_init__` to set `self._session._credentials = self._credentials`, ensuring all boto3 clients created from `RefreshableSession` use the refreshable credentials source of truth provided to `RefreshableCredentials | DeferredRefreshableCredentials`. After this change, refreshable credentials are used consistently everywhere, irrespective of setup.
565
+
566
+ #### ✂️ v6.2.3
567
+
568
+ - The `RefreshableTemporaryCredentials` type hint was deprecated in favor of `TemporaryCredentials`.
569
+ - `expiry_time` was added as a parameter returned by the `refreshable_credentials` method and `credentials` attribute.
@@ -0,0 +1,18 @@
1
+ boto3_refresh_session/__init__.py,sha256=ZVywXE56rxtLErLk1k-mQKBxf8NWS4IcBfQTH0lWKq4,415
2
+ boto3_refresh_session/exceptions.py,sha256=uS0tcAl9UZoCvktOz08GC59JDNV4ml-su8CVUs0qzNw,1287
3
+ boto3_refresh_session/methods/__init__.py,sha256=FpwWixSVpy_6pUe1u4fXmjO-_fDH--qTk_xrMnBCHxU,193
4
+ boto3_refresh_session/methods/custom.py,sha256=i07paDNtzi_92Bqc7Pk4cEVfKPV5okEOGHyXipp6HWQ,5136
5
+ boto3_refresh_session/methods/iot/__init__.py,sha256=wIYp7HFZ_Q8XEHwWmpKjDNXxBm29C0RisP_9GSVwzZI,147
6
+ boto3_refresh_session/methods/iot/core.py,sha256=K9Zcwpu4yPD51Pz9ImXFDc9XswPQhTlHU-DxwbPU5Bo,1218
7
+ boto3_refresh_session/methods/iot/x509.py,sha256=3dk0616bQI47pVyPV05vrdtNcTS-SEHablrehy2XPAM,21332
8
+ boto3_refresh_session/methods/sts.py,sha256=ZX5yM0n5pMmmieNmOYDR1bGdZ4Y0m7PHIylabI5Q9rg,9124
9
+ boto3_refresh_session/session.py,sha256=EMydUVFLdghH3La0nGCnZeZJHt4xWqumgJEMf3iCTBo,3359
10
+ boto3_refresh_session/utils/__init__.py,sha256=wll77Z3SIQCfJqOKjSZC1EjXUT-7KOB31u6Fl4FLjkY,214
11
+ boto3_refresh_session/utils/cache.py,sha256=NEDu8bS_wj3O0KQpHnhqZAYsUE4-Xs0Ec5YqzWsK2tI,2836
12
+ boto3_refresh_session/utils/internal.py,sha256=VBKgPTdqyT6slOGu6XrdDE4CCwtj4dK15LpNuR0Ssr8,14546
13
+ boto3_refresh_session/utils/typing.py,sha256=DW5sm-KPi5wetadJXwkkTpwEGx5KiriBkXIAGcWVYSI,3171
14
+ boto3_refresh_session-6.2.7.dist-info/METADATA,sha256=aS1YDiaOMe_Get_LcLheh-AzTX7uG4QopI9VQzTiYXY,26548
15
+ boto3_refresh_session-6.2.7.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
16
+ boto3_refresh_session-6.2.7.dist-info/licenses/LICENSE,sha256=I3ZYTXAjbIly6bm6J-TvFTuuHwTKws4h89QaY5c5HiY,1067
17
+ boto3_refresh_session-6.2.7.dist-info/licenses/NOTICE,sha256=1s8r33qbl1z0YvPB942iWgvbkP94P_e8AnROr1qXXuw,939
18
+ boto3_refresh_session-6.2.7.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.1.3
2
+ Generator: poetry-core 2.2.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any